硒/爪哇返回错误没有这样的元素:无法找到元素

发布于 2025-01-31 10:58:48 字数 1858 浏览 6 评论 0 原文

我正在尝试单击页面上的“新车辆搜索”,但在我看来,我对此有错误的Web元素定位器(XPATH或CSS)。我尝试了所有可能的选项(CSS,xpath ..),但我有一个错误:

blockquote

[error] nosuchelementException: 没有这样的元素:无法找到元素:{“方法”:“ xpath”,“ selector”:“/html/body/div [5]/div/div/div [4]/div 1 /div [2]“} (会话信息:chrome = 101.0.4951.67)

blockquote

[新车辆搜索按钮 - 无法找到元素] 1

睡眠(10000);

driver.findelement(by.xpath(“/html/hod body/div [5]/div/div/div [4]/div 1 /div [2])/div [2]) 。点击();

blockquote

I am trying to click "New Vehicle Search" on the page, but it seems to me I have the wrong web element locator (XPath or CSS) for this. I tried all possible options (CSS, XPath..) without success and I got an error:

Blockquote

[ERROR] NoSuchElementException:
no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[5]/div/div[4]/div1/div[2]"}
(Session info: chrome=101.0.4951.67)

Blockquote

[New Vehicle Search button-Unable to locate the element] 1

sleep(10000);

driver.findElement(By.xpath("/html/body/div[5]/div/div[4]/div1/div[2]")).click();

Blockquote

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屋顶上的小猫咪 2025-02-07 10:58:48

使用浏览器检查器并将该XPath复制到Element Search中。如果找不到任何东西,您的XPath无效。

您可能需要检查元素是否位于iFrame内部,这需要您先切换到该框架。

Use browser inspector and copy that xpath into element search. If it doesn't find anything, your xpath doesn't work.

You may need to check if the elements are located inside an iframe, which requires you to switch to that frame first.

仙女山的月亮 2025-02-07 10:58:48

该元素的类似乎在该网页上是唯一的,也许您可​​以尝试按课堂定位?

driver.findElement(By.className("store-ymm-newvehsearch"))

The class of the element seems to be unique on that webpage, maybe you can try locating it by class?

driver.findElement(By.className("store-ymm-newvehsearch"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文