Python 2.7 Selenium Python在字符串中包含引号时抛出错误

Python 2.7 Selenium Python在字符串中包含引号时抛出错误,python-2.7,selenium,xpath,selenium-webdriver,Python 2.7,Selenium,Xpath,Selenium Webdriver,我正在验证元素中是否存在某些文本。文本在字符串中包含一个引号。我的方法是断言错误。我希望它是真的,因为文本在GUI上 我没有在字符串中正确地包含引号。请问正确的语法是什么 当我使用调试器检查代码时,它会显示: overwritten_element.text = {unicode} u'One or more reports use the \\'default\\'prefix and will be overwritten. Do you wish to continue? 我的方法是:

我正在验证元素中是否存在某些文本。文本在字符串中包含一个引号。我的方法是断言错误。我希望它是真的,因为文本在GUI上

我没有在字符串中正确地包含引号。请问正确的语法是什么

当我使用调试器检查代码时,它会显示:

overwritten_element.text = {unicode} u'One or more reports use the \\'default\\'prefix and will be overwritten.  Do you wish to continue?
我的方法是:

def is_save_overwrite_dialog_displayed(self): 
        overwritten_element = self.get_element(By.ID, 'message_dialog_question_content')
        return overwritten_element.text == r"One or more reports use the 'default' prefix and will be overwritten.  Do you wish to continue?"
带引号的字符串是: 一个或多个报告使用“默认”前缀,将被覆盖。你想继续吗

我试过了

r"One or more reports use the 'default' prefix and will be overwritten.  Do you` wish to continue?"
我试过:

r"One or more reports use the \\'default\\' prefix and will be overwritten.  Do you wish to continue?"
HTML是:

<div id="message_dialog_question_content">
<div>One or more reports use the 'default' prefix and will be overwritten.  Do you wish to continue?</div>
</div>
谢谢,
Riaz创建了一个类似的测试,它揭示了问题不在于引号,而在于双空格

上述测试输出

>       assert elem.text == compare
E       assert 'One or more ... to continue?' == 'One or more r... to continue?'
E         Skipping 60 identical leading characters in diff, use -v to show
E         - rwritten. Do you wish to continue?
E         + rwritten.  Do you wish to continue?
E         ?           +
---------- Captured stdout call ----------
length of elem : 94, length of compare : 95

创建了一个类似的测试,它揭示了问题不在于引号,而在于双空格

上述测试输出

>       assert elem.text == compare
E       assert 'One or more ... to continue?' == 'One or more r... to continue?'
E         Skipping 60 identical leading characters in diff, use -v to show
E         - rwritten. Do you wish to continue?
E         + rwritten.  Do you wish to continue?
E         ?           +
---------- Captured stdout call ----------
length of elem : 94, length of compare : 95

Do
之前的这个双空格是故意的吗?
overwrited\u元素.text的确切值是多少?当我检查html时,在DoI遍历代码之前它有一个双空格,在overwrited\u元素.text处放一个断点。该值显示Overwrited_element.text={unicode}u'一个或多个报表使用\\'default\\'前缀,将被覆盖。是否要继续?是否可以执行
“”。在“您的文本”中为c加入(十六进制(ord(c))
在两个字符串上显示差异?在
Do
之前这个双空格是故意的吗?覆盖的\u元素text的确切值是多少?当我检查html时,在DoI遍历代码之前它有一个双空格,在覆盖的\u元素.text处放一个断点。该值显示Overwrited_element.text={unicode}u'一个或多个报表使用\\'default\\'前缀,将被覆盖。是否要继续?能否在两个字符串上执行
“”。在“您的文本”中为c连接(十六进制(ord(c))
,并说明差异?
>       assert elem.text == compare
E       assert 'One or more ... to continue?' == 'One or more r... to continue?'
E         Skipping 60 identical leading characters in diff, use -v to show
E         - rwritten. Do you wish to continue?
E         + rwritten.  Do you wish to continue?
E         ?           +
---------- Captured stdout call ----------
length of elem : 94, length of compare : 95