Python 如何让selenium识别带有撇号的搜索

Python 如何让selenium识别带有撇号的搜索,python,selenium,Python,Selenium,我制作了一个脚本,将学生成绩和评论从我的谷歌表格上传到D2L。 为了让selenium输入带有注释文本框的iframe,我搜索名字和姓氏。这对我来说去年一整年都很有效。今年我的名字包括“作为姓氏的一部分”,例如詹姆斯·达西。硒不喜欢这样 有没有简单的方法让撇号被识别?或者是一种不需要精确匹配的搜索方式 for i in toplist: # copies and pastes in comments icnFeedback = "//a[contains(@title,'"

我制作了一个脚本,将学生成绩和评论从我的谷歌表格上传到D2L。 为了让selenium输入带有注释文本框的iframe,我搜索名字和姓氏。这对我来说去年一整年都很有效。今年我的名字包括“作为姓氏的一部分”,例如詹姆斯·达西。硒不喜欢这样

有没有简单的方法让撇号被识别?或者是一种不需要精确匹配的搜索方式

 for i in toplist:  # copies and pastes in comments 
        icnFeedback = "//a[contains(@title,'"+ i[0]+"') and @class='d2l-imagelink']" #i[0] is students name, looking that it is contained in title. 
        comments = i[1]  # i[1] is student comment

        wait.until(EC.element_to_be_clickable((By.XPATH, icnFeedback)))
        myElement = driver.find_element_by_xpath(icnFeedback)   # find user by names
        driver.execute_script("arguments[0].click();", myElement)   #clicks the feedback button

看起来可能会发生这种情况,因为您正在使用单引号同时包含字符串(
i[0]
),并且字符串本身中有一个单引号。发生这种情况时,查询将丢失其结构

false\u ln=“las'tname”
xpath=“//a[包含(@title,“+fake_ln+”)和@class='d2l-imagelink']
打印(xpath)
#输出://a[包含(@title,'las'tname')和@class='d2l-imagelink']
这是一个问题,因为现在不仅姓氏在引号中,您还将
)和@class=
放在引号中

试试这个:

icnFeedback='//a[包含(@title,“+i[0]+”)和@class=“d2l imagelink”]

您是否收到错误?引发TimeoutException(消息、屏幕、堆栈跟踪)selenium.common.exceptions.TimeoutException:message:它只是一直在搜索,但撇号会扰乱搜索