繁体   English   中英

硒:Concat xpath函数在Internet Explorer中不起作用

[英]selenium: Concat xpath function is not working in internet explorer

我在Internet Explorer 10中执行和xpath功能时遇到问题。它与Firefox甚至Chrome都可以完美运行,但IE失败了。 我需要搜索以下错误消息:

We cannot find this car, please click on "I don't know my car reg" above

此消息的问题是双引号和不加引号。

无法使用:

//span[@id='id']//*[text()='We cannot find this car, please click on "I don't know my car reg" above']

要么

//span[@id='id']//*[text()="We cannot find this car, please click on "I don't know my car reg" above"]

所以我尝试了这个:

//span[@id='id']//*[text()=concat('We cannot find this car, please click on "I don',"'",'t know my car reg" above')]'

concat函数在chrome和fiferox中完美运行,但是在IE中,我遇到以下异常:

org.openqa.selenium.InvalidSelectorException: The xpath expression '//span[@id='quoteForm:registrationLookupPart:m1']//*[text()=concat('We cannot find this car, please click on "I don',"'",'t know my car reg" above')]' cannot be evaluated or does notresult in a WebElement (WARNING: The server did not provide any stacktrace information)

有谁知道为什么Selenium IE驱动程序会引发此异常?

它看起来像concat函数,或者对于IE不存在,或者不能以相同的方式工作。 这是真的吗?

非常感谢

IE没有提供本机的xpath实现,因此selenium必须提供自己的实现,这很可能就是这种情况之一。 一般建议不要使用xpath(如果不需要的话),而应使用CSS选择器,因为这样做的速度要快得多。 我不确定这是否可能,因为您尚未发布html。

有两个选择:

在XPath中使用部分文本匹配:

//*[contains(text(), "We cannot find this car, please click on")]

通过类名称查找元素:

findElement.ByClass("rich-message-label");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM