gpt4 book ai didi

java - Selenium - 错误 : The expression is not a legal expression for xpath

转载 作者:行者123 更新时间:2023-12-01 17:48:10 24 4
gpt4 key购买 nike

在网站 [ https://javapapers.com/core-java/java-qr-code/]如果我在浏览器中搜索具有以下 xpath 的元素

//div[@id='tutorial-body']/p/img

我得到了两个匹配项,但是如果我在 Selenium 代码中使用相同的东西

WebDriver driver = new FirefoxDriver();
driver.get("https://javapapers.com/core-java/java-qr-code/");
Thread.sleep(2000);
WebElement qr_url = driver.findElement(By.xpath("//div[@id='tutorial-body']/p/img/"))
String l =qr_url.getCssValue("src");

我收到以下错误:

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: Given xpath expression "//div[@id='tutorial-body']/p/img/" is invalid: SyntaxError: The expression is not a legal expression.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html

那么我的 Xpath 出了什么问题?

最佳答案

只需删除表达式末尾多余的斜杠:

"//div[@id='tutorial-body']/p/img/" --> "//div[@id='tutorial-body']/p/img"

关于java - Selenium - 错误 : The expression is not a legal expression for xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53003614/

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