【发布时间】:2013-01-16 17:43:27
【问题描述】:
我已经在构建之外运行了一段时间的自动化测试,但围绕电子邮件验证的一系列测试一直失败。我发现的问题是由于引发的 javascript 错误导致 Selenium 无法在 XPath 中的文本中搜索“@”。
我遇到了这个SO Question,它很好地向我证实了无法通过 Selenium 中的 XPath 作为标准在文本中搜索字符。
我的问题是,有没有人找到解决办法?
例如,我希望能够找到具有以下文本字段的元素:
<h1>"personA@email.com.au.personB@email.com.au - The separator '@' is either in an invalid position or is missing from the address."</h1>
而我当前引发 javascript 错误的 XPath(显然不适用于存在符号)是(其中 errorText 就是上面的字符串):
"//*[contains(text(), '" + errorText + "')]"
只是为了好玩,如果 javascript 错误有帮助的话:
[14/01/2013 - 14:35:00.1820111] : InvalidSelectorError: Unable to locate an element with the xpath expression //*[contains(text(), 'personA@email.com.au.personB@email.com.au - The separator '@' is either in an invalid position or is missing from the address.')] because of the following error:
Error: Bad token: @
[编辑]
我查看了SO Question,这表明我需要用双引号将我的输入文本括起来,但是这样做仍然会导致上述 javascript 错误抛出。我仍然认为@符号是这里的问题,并且看不到通过包含它的文本进行搜索的明显方法。
【问题讨论】: