gpt4 book ai didi

selenium - 给定 xpath 表达式 "//div[contains(@class=' loader-overlay')]"对 Selenium 无效

转载 作者:行者123 更新时间:2023-12-03 16:01:45 25 4
gpt4 key购买 nike

从 2.53 版升级到 3.14 版后,Selenium 说

给定的 xpath 表达式“//div[contains(@class='loader-overlay')]”无效

这段代码

System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver/v0.23.0");
FirefoxOptions options = new FirefoxOptions();
//...
driver = new FirefoxDriver(options);
WebElement loaderElement = driver.findElement(By.xpath("//div[contains(@class='loader-overlay')]"));

产生这个错误

org.openqa.selenium.InvalidSelectorException: Given xpath expression "//div[contains(@class='loader-overlay')]" is invalid: [Exception... "<no message>"  nsresult: "0x8060000d (<unknown>)"  location: "JS frame :: chrome://marionette/content/element.js :: element.findByXPath :: line 401"  data: no]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'xxx', ip: '10.233.112.79', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-116-generic', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 64.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 2736, moz:profile: /tmp/rust_mozprofile.OP8KKQ..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, platformVersion: 4.4.0-116-generic, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

最佳答案

你需要更换

//div[contains(@class='loader-overlay')]

//div[contains(@class, 'loader-overlay')]

请注意,如果您想检查属性值是否恰好是 “value”,您应该使用 [@attr = "value"] 语法,但是 contains 语法是 [contains(@attr, "value")]

关于selenium - 给定 xpath 表达式 "//div[contains(@class=' loader-overlay')]"对 Selenium 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54217485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com