【发布时间】:2020-02-16 20:50:39
【问题描述】:
我正在尝试点击支付弹出窗口中的一个元素:
<label data-v-533987c6="" xpath="1">Card Number:</label>
<input data-v-533987c6="" type="tel" data-mask="#### #### #### ####" data-previous-value="" xpath="1">
使用以下 xPath:
@FindBy(name = "//div[contains(@class,'buy-tickets')]//div/label[text()='卡号:']/following-sibling::input")
但我收到此错误:
org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified
(Session info: chrome=80.0.3987.87)
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: 'DESKTOP-VQ56FMV', ip: '192.168.0.13', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.87, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: C:\Users\Nastya\AppData\Loc...}, goog:chromeOptions: {debuggerAddress: localhost:64958}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 3ca3f388f2b3cf47642733a6f03...}
Session ID: 3ca3f388f2b3cf47642733a6f0383c1e
*** Element info: {Using=name, value=//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input}
为什么?希望你能帮帮我!
【问题讨论】:
-
导致问题的选择器不是您发布的选择器,而是消息在最后一行报告的选择器 (//div[contains(@class,'buy-tickets')]/ /div/label[text()='Card Number:']/following-sibling::input} ) 您能否确认您实际上使用的是使用 XPath 提取的代码,而不是使用 CSS 选择器?
标签: java selenium selenium-webdriver xpath selenide