简体   繁体   English

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

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

I am having issues executing and xpath function in Internet Explorer 10. It works perfectly with Firefox and even Chrome, but with IE is failing. 我在Internet Explorer 10中执行和xpath功能时遇到问题。它与Firefox甚至Chrome都可以完美运行,但IE失败了。 I need to search the following error message: 我需要搜索以下错误消息:

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

The problem with this message is the double quotes and the quote on the don't. 此消息的问题是双引号和不加引号。

Is impossible to use: 无法使用:

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

or 要么

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

So i tried this: 所以我尝试了这个:

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

The concat function works perfectly in chrome and fiferox but in IE i got the following exception: 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)

Does anyone know why Selenium IE driver throws this exception? 有谁知道为什么Selenium IE驱动程序会引发此异常?

It looks like the concat function or does not exists for IE or does not work the same way. 它看起来像concat函数,或者对于IE不存在,或者不能以相同的方式工作。 Would this be true? 这是真的吗?

Thanks a lot 非常感谢

IE provides no native xpath implementation so selenium has to provide its own and it may well be that this is one of the cases it falls down on. IE没有提供本机的xpath实现,因此selenium必须提供自己的实现,这很可能就是这种情况之一。 The general recommendation is to never use xpath if you do not have to and instead use css selectors as this work much faster. 一般建议不要使用xpath(如果不需要的话),而应使用CSS选择器,因为这样做的速度要快得多。 I am not sure this is possible for you have not posted the html. 我不确定这是否可能,因为您尚未发布html。

A couple of options: 有两个选择:

Use a partial text match within your XPath: 在XPath中使用部分文本匹配:

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

Find the element by class name: 通过类名称查找元素:

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

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

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