使用Python Selenium,如何使用特殊字符验证所选选项文本?
我的选择选项(选定)文本已附加文本:&n b s p; ; ;&n b s p✔;这会产生一个复选标记(✔) 前面有一些空格 类似HTML的:使用Python Selenium,如何使用特殊字符验证所选选项文本?,python,selenium,python-unicode,Python,Selenium,Python Unicode,我的选择选项(选定)文本已附加文本:&n b s p; ; ;&n b s p✔;这会产生一个复选标记(✔) 前面有一些空格 类似HTML的: <label for="PSME">PSME:<select id="PSME" name="PSME"><option value="someuniquenumbershere" selected="selected">Lname, Fname  
<label for="PSME">PSME:<select id="PSME" name="PSME"><option value="someuniquenumbershere" selected="selected">Lname, Fname ✔</option>
<option value="">------------</option>
<option value="someuniquenumbershere">.... lots of options here
此代码从不与option.text匹配,且“if”中的结果为true。
如何使此“if”与option.text匹配
我将结果捕获到日志中,并验证了元素是否正确,代码运行时没有错误,当然“if option.text==”与self.TestUserName+不匹配&nbs-p;&nbs-p;&nbs-p;&nbs-p;&nbs-p;&nbs-p;&x27-14;”
{是的,我读过“每个软件开发人员绝对、肯定必须了解Unicode和字符集的绝对最低要求(没有借口!)”,而且该页面确实包含谢谢Python没有某种String.trim()函数吗?当然有:“strip()”,但复选标记需要验证,并且可以更改为我也需要验证的其他内容。因此这是一个字符编码问题?您是否可以改为读取其中一个属性,例如
@选定的?是的,它似乎是一个字符编码的东西,我想验证文本。if option.text.endswith(u' 2 7 1 4;)
PSMEMatch = False
try:
for option in CPSMEElement.find_elements_by_tag_name('option'):
if option.text == self.TestUserName + " ✔":
PSMEMatch = True
break