Selenium Web Driver& Java的。元素在点(x,y)处不可点击。其他元素将收到点击 [英] Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click

查看:141
本文介绍了Selenium Web Driver& Java的。元素在点(x,y)处不可点击。其他元素将收到点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了明确的等待并且有警告:

I used explicit waits and I have the warning:


org.openqa.selenium.WebDriverException:
元素不是可点击(36,72)。其他元素将获得
点击:...
命令持续时间或超时:393毫秒

org.openqa.selenium.WebDriverException: Element is not clickable at point (36, 72). Other element would receive the click: ... Command duration or timeout: 393 milliseconds

如果我使用 Thread.sleep(2000)我没有收到任何警告。

If I use Thread.sleep(2000) I don't receive any warnings.

@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);
}


推荐答案

WebDriverException:元素无法点击在点(x,y)



这是一个典型的 org.openqa.selenium.WebDriverException 扩展 java.lang.RuntimeException

WebDriverException: Element is not clickable at point (x, y)

This is a typical org.openqa.selenium.WebDriverException which extends 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

关于您的个人用例,错误告诉所有:

About your individual usecase, the error tells it all :

WebDriverException: Element is not clickable at point (x, y). Other element would receive the click 

从您的代码块可以清楚地看出,您已经定义了等待 as WebDriverWait wait = new WebDriverWait(driver,10); 但是你正在调用 click()在 ExplicitWait 之前的元素上的方法在中起作用,直到(ExpectedConditions.elementToBeClickable)

It is clear from your code block that you have defined the wait as WebDriverWait wait = new WebDriverWait(driver, 10); but you are calling the click() method on the element before the ExplicitWait comes into play as in until(ExpectedConditions.elementToBeClickable).

错误 元素在点(x)无法点击,y) 可能来自不同的因素。您可以通过以下任一程序解决这些问题:

The error Element is not clickable at point (x, y) can arise from different factors. You can address them by either of the following procedures:

1。由于存在JavaScript或AJAX调用而未被点击的元素

尝试使用 操作 类:

Try to use Actions Class:

WebElement element = driver.findElement(By.id("navigationPageButton"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();

2。元素未被点击,因为它不在视口

2. Element not getting clicked as it is not within Viewport

尝试使用 JavascriptExecutor 将元素放入视口中:

Try to use JavascriptExecutor to bring the element within the Viewport:

WebElement myelement = driver.findElement(By.id("navigationPageButton"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement); 

3。页面在元素可点击之前会刷新。

在这种情况下,诱导 ExplicitWait WebDriverWait ,如第4点所述。

In this case induce ExplicitWait i.e WebDriverWait as mentioned in point 4.

4。元素存在于DOM中但不可点击。

在这种情况下,诱导 ExplicitWait ExpectedConditions 设置为 elementToBeClickable 要点击的元素:

In this case induce ExplicitWait with ExpectedConditions set to elementToBeClickable for the element to be clickable:

WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));

5。元素存在但具有临时叠加。

在这种情况下,诱导 ExplicitWait ExpectedConditions 设置为 invisibilityOfElementLocated 隐藏。

In this case induce ExplicitWait with ExpectedConditions set to invisibilityOfElementLocated for the Overlay to be invisible.

WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));

6。元素存在但具有永久叠加。

使用 JavascriptExecutor 直接在元素上发送点击。

Use JavascriptExecutor to send the click directly on the element.

WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);

这篇关于Selenium Web Driver& Java的。元素在点(x,y)处不可点击。其他元素将收到点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆