java - 元素 MyElement 在点 (x, y) 处不可点击...其他元素将收到点击

标签 java selenium selenium-webdriver webdriver katalon-studio

我正在尝试使用基于 selenium 的 Katalon Studio 进行一些测试。在我的一项测试中,我必须在文本区域内写入。问题是我收到以下错误:

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

事实上,我的元素位于其他可能隐藏它的元素内,但如何使点击事件击中我的文本区域?

最佳答案

元素...在点 (x, y) 处不可单击。其他元素也会收到点击可能是由不同因素引起的。您可以通过以下任一过程来解决这些问题:

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

尝试使用Actions类:

WebElement element = driver.findElement(By.id("id1"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
  • 元素未被点击,因为它不在 Viewport
  • 尝试使用 JavascriptExecutor 将元素引入视口(viewport):

    JavascriptExecutor jse1 = (JavascriptExecutor)driver;
    jse1.executeScript("scroll(250, 0)"); // if the element is on top.
    jse1.executeScript("scroll(0, 250)"); // if the element is at bottom.
    

    或者

    WebElement myelement = driver.findElement(By.id("id1"));
    JavascriptExecutor jse2 = (JavascriptExecutor)driver;
    jse2.executeScript("arguments[0].scrollIntoView()", myelement); 
    
  • 在元素可点击之前页面已刷新。
  • 在这种情况下会引起一些等待

  • 元素存在于 DOM 中,但不可点击。
  • 在本例中,添加一些 ExplicitWait 以使元素可点击。

    WebDriverWait wait2 = new WebDriverWait(driver, 10);
    wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));
    
  • 元素存在,但具有临时叠加层。
  • 在这种情况下,诱导 ExplicitWait 并将 ExpectedConditions 设置为 invisibilityOfElementLocated 使覆盖层不可见。

    WebDriverWait wait3 = new WebDriverWait(driver, 10);
    wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
    
  • 元素存在,但具有永久叠加层。
  • 使用 JavascriptExecutor 直接发送对元素的点击。

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

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

    相关文章:

    java - 我在ubuntu中使用maven,.java,sts eclipse和selenium ide,svn和web驱动程序

    java - 如何制作WebDriver项目的Java可执行Jar文件

    java - Struts2 教程在 .action 页面上给出 404

    java - 如何在Spring中使用WebLogic提供的JNDI DataSource?

    python - Splinter,打开浏览器但无法访问网页

    javascript - 单击 iframe 中的元素 - Selenium Python

    java - 等待一个浏览器完成操作并在 selenium webdriver 中的另一个浏览器中继续

    java - OAuth2 和 OAuth3 之间的区别?

    java - volatile 和 static 关键字有什么区别?

    java.lang.NoClassDefFoundError ANT 构建