我使用了明确的等待,我有警告:
org.openqa.selenium.WebDriverException:元素在点(36,72)处不可点击 . 其他元素将收到点击:...命令持续时间或超时:393毫秒
如果我使用 Thread.sleep(2000)
我没有收到任何警告 .
@Test(dataProvider = "menuData")
public void Main(String btnMenu, String TitleResultPage, String Text) throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 10);
driver.findElement(By.id("navigationPageButton")).click();
try {
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu)));
} catch (Exception e) {
System.out.println("Oh");
}
driver.findElement(By.cssSelector(btnMenu)).click();
Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(), Text);
}
5 回答
你可以试试
我试图点击一些元素(或它的叠加层时遇到了这个错误,我没有为我工作 . 我通过使用
elementFromPoint
DOM API来修复它,找到Selenium希望我点击的元素:我也有过元素移动的情况,例如因为页面上方的元素正在进行动画展开或折叠 . 在这种情况下,这个预期条件课程有所帮助 . 你给它动画的元素,而不是你想要点击的元素 . 此版本仅适用于jQuery动画 .
将页面滚动到异常中提到的附近点对我来说是个窍门 . 以下是代码段:
NOTE: 我用Facebook php webdriver
WebDriverException:元素在点(x,y)处不可点击
这是一个典型的org.openqa.selenium.WebDriverException,它扩展了 java.lang.RuntimeException .
此例外的字段是:
BASE_SUPPORT_URL: protected static final java.lang.String BASE_SUPPORT_URL
DRIVER_INFO: public static final java.lang.String DRIVER_INFO
SESSION_ID: public static final java.lang.String SESSION_ID
关于您的个人用例,错误告诉所有:
从代码块可以清楚地看出,您已将
wait
定义为WebDriverWait wait = new WebDriverWait(driver, 10);
,但是在ExplicitWait
发挥作用之前,您正在调用元素上的click()
方法,如until(ExpectedConditions.elementToBeClickable)
.解决方案
错误 Element is not clickable at point (x, y) 可能来自不同的因素 . 您可以通过以下任一过程解决它们:
1. Element not getting clicked due to JavaScript or AJAX calls present
尝试使用 Actions 类:
2. Element not getting clicked as it is not within Viewport
尝试使用 JavascriptExecutor 将元素放在视口中:
3. The page is getting refreshed before the element gets clickable.
在这种情况下,如第4点所述,诱导 ExplicitWait 即 WebDriverWait .
4. Element is present in the DOM but not clickable.
在这种情况下,将 ExplicitWait 与 ExpectedConditions 设置为 elementToBeClickable ,以便可点击元素:
5. Element is present but having temporary Overlay.
在这种情况下,将 ExplicitWait 与 ExpectedConditions 设置为 invisibilityOfElementLocated ,以使Overlay不可见 .
6. Element is present but having permanent Overlay.
使用
JavascriptExecutor
直接在元素上发送单击 .如果您需要使用Javascript
我们可以使用参数[0] .click()来模拟点击操作 .