【发布时间】:2019-12-24 18:21:17
【问题描述】:
我正在尝试单击一个元素。当我在 chrome 浏览器上运行测试脚本时,元素被点击,当我在边缘浏览器上运行时,相同的测试脚本给出异常“InvalidSelectorException”
在 chrome-[https://cdn1.imggmi.com/uploads/2019/8/20/83d0add716dce6bdb5d8b1c6bac09544-full.png]] 中找到的元素图像
在边缘找到的元素图像 - [https://cdn1.imggmi.com/uploads/2019/8/20/6333dff18caf14f7440955587ee98228-full.png]
代码中使用的Xpath:
driver.findElement(By.xpath("//a[contains(text(),'Dashboard')]"))
我们可以看到边缘浏览器中的“仪表板”元素文本中没有引号,而 chrome 中的元素文本中有引号。
这就是边缘选择器无效的原因吗?
Dashboard.java:173 - Exception occured :
org.openqa.selenium.InvalidSelectorException: The specified selector is
invalid.
For documentation on this error, please visit:
https://www.seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-
14T08:17:03'
System info: host: 'IND-L-SRAWAT', ip: '164.99.196.169', os.name:
'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version:
'1.8.0_201'
Driver info: org.openqa.selenium.edge.EdgeDriver
Capabilities {acceptInsecureCerts: false, browserName: MicrosoftEdge,
browserVersion: 44.17763.1.0, javascriptEnabled: true, pageLoadStrategy:
normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), s
etWindowRect: false, timeouts: {implicit: 0, pageLoad: 300000, script:
30000}}
Session ID: 4BC8634F-5CCA-4747-BE2F-B7E4A0D59872
*** Element info: {Using=xpath, value=//a[contains(text(),'Dashboard')]}
2019-08-19 17:02:44 INFO SettingsUIOperationsTest.java:104 - Test Case
Failed
谁能帮我解决这个问题?
**** - 编辑 ****
我知道了
- .contains(某些文本)
- 和 Xpath 中的条件
- " ' " 双引号内的单引号
这些都不适用于 IE 或 Edge
我用 Partial Link Text 尝试了相同的 xpath,它成功了。
谁能解释一下?
【问题讨论】:
标签: selenium selenium-webdriver xpath selenium-chromedriver microsoft-edge