加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

Selenium Web驱动程序和Java。元素在点(36,72)处不可点击。其他

发布时间:2020-12-14 21:17:28 所属栏目:资源 来源:网络整理
导读:我使用Explicit Waits并且我有警告: 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)我没
我使用Explicit Waits并且我有警告:

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)我没有收到任何警告。

@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。

此例外的字段是:

> 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

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

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

从代码块中可以清楚地看出,您已将等待定义为WebDriverWait wait = new WebDriverWait(driver,10);但是你要在ExplicitWait进入播放之前调用元素上的click()方法,直到(ExpectedConditions.elementToBeClickable)。

错误元素在点(x,y)处不可点击可能由不同因素引起。您可以通过以下任一过程解决它们:

1.由于存在JavaScript或AJAX调用,元素未被点击

尝试使用Actions类:

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

2.元素未被点击,因为它不在Viewport之内

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

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

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

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

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

在这种情况下,将ExlicitWait与ExpectedConditions一起设置为elementToBeClickable,以使元素可被点击:

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

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

在这种情况下,将ExlicitWait与ExpectedConditions设置为invisibilityOfElementLocated,以使Overlay不可见。

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

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读