[英]Selenium internet explorer click function not working properly
[英]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.