Firefox中的Selenium"Element is not clickable at point"错误

eme*_*ery 7 firefox webdriver selenium-webdriver

关于Webdriver错误

Element is not clickable at point (X, Y). Another element would recieve the click instead.
Run Code Online (Sandbox Code Playgroud)

对于ChromeDriver,这是在调试"元素在点上无法点击"错误中解决的,但是问题也可能在Firefox中发生.

FirefoxDriver中出现这种情况时解决此问题的最佳方法是什么?

小智 5

这发生在以下情况-

  • 当元素加载到 DOM 中,但在 UI 上的位置不固定时。可能有一些其他 div 或图像未完全加载。

  • 在单击元素之前页面正在刷新。

解决方法

  • 在 UI 中的每个 Web 元素上执行操作之前使用 Thread.sleep,但这不是一个好主意。
  • 使用 WebDriverWait 预期条件。

我遇到了同样的问题,页面加载时间更长,加载图标在整个网页上重叠。

为了解决这个问题,我实现了 WebDriverWait ExpectedConditions,它在对元素执行单击操作之前等待加载图标消失

在执行操作之前调用此函数(我正在使用数据驱动框架)

public void waitForLoader () throws Exception  {
  try {
   String ObjectArray[]=ObjectReader.getObjectArray("LoadingIcon"); 
    if(checkElementDisplayed(ObjectArray[3],ObjectArray[2]))
    {
     WebDriverWait wait = new WebDriverWait(remotewebdriver,10); 
     wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(ObjectArray[3])));
    }
   } catch (NoSuchElementException e) {
   System.out.println("The page is loaded successfully");
   }
  }
Run Code Online (Sandbox Code Playgroud)


eme*_*ery 2

仔细匹配 Selenium jar 版本与 Firefox 版本可以解决该问题。如果元素不在页面上,Selenium 应该自动将其滚动到视图中。使用 JavaScript 强制元素进入视图是不必要的。

我们在使用 selenium-server-standalone-2.44.0.jar 的 Firefox 31.5.0中从未看到此问题,但是当使用 selenium-server-standalone-2.52.0.jar 升级到 Firefox 38.7.0 时,它成为一个问题。

请参阅https://github.com/seleniumhq/selenium/issues/1543