gpt4 book ai didi

java - Chromedriver 元素在点 (xxx, yyy) 处不可点击。其他元素将收到点击 :

转载 作者:行者123 更新时间:2023-12-02 04:23:24 24 4
gpt4 key购买 nike

将 Chromedriver 与 Selenium 结合使用时,我遇到以下可怕的错误:

"org.openqa.selenium.WebDriverException: Element is not clickable at point (xxx, yyy). Other element would receive the click: ..."

我知道这已经被讨论过 here

但是我的情况有点不同,如果我延迟大约 5 秒然后单击它就可以正常工作。我不需要做任何特别的事情,只需等待即可。

我知道我可以使用 JS 或 Actions 强制单击,但我想要一种更优雅的方式来处理此问题,即仅在按钮变为可单击时单击按钮。问题是我不知道如何检查按钮是否可点击。

我尝试了以下方法,但都不起作用:

1) ExpectedConditions.elementToBeClickable
2) ExpectedConditions.visibilityOf

有什么想法吗?

最佳答案

我可以想到您可以尝试的两种选择:

JavaScript

检查描述文档加载状态的Document.readyState属性:

JavascriptExecutor jsExecutor = (JavascriptExecutor) input;
return jsExecutor.executeScript("return document.readyState;").equals("complete");

您只需等待它“完成”即可。在很多情况下可能行不通,但值得一试。

循环

这可能是最简单的解决方案。不确定它的优雅性,但应该完成这项工作,而不会浪费比需要更多的时间(这只是一个非常基本的示例,不应按原样使用此代码):

while (true) {
try {
element.click();
} catch (WebDriverException e) {
// ignore
Thread.sleep(millis);
}

关于java - Chromedriver 元素在点 (xxx, yyy) 处不可点击。其他元素将收到点击 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32490572/

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