【问题标题】:Unable to locate element unknown error: Element . Other element would receive the click: <div class="loading-wrapper" [duplicate]无法找到元素未知错误:元素。其他元素会收到点击:<div class="loading-wrapper" [重复]
【发布时间】:2019-06-08 05:24:13
【问题描述】:

我正在尝试通过 XPath 定位元素:我尝试添加等待加载页面并尝试向下滚动页面。但同样的错误

driver.findElement(By.xpath("//text()[contains(.,'添加投资组合')]/ancestor::a[1]")).click();

未知错误:元素 ... 在点 (326, 302) 处不可点击。其他元素会收到点击:...

【问题讨论】:

  • 它不同的答案是工作

标签: java selenium automation automated-tests


【解决方案1】:
  1. 添加 ExplicitWait 以等待元素可见/可点击

     webDriverWait waitForElement = WebDriverWait(new TimeSpan(0, 0, 15));
     waitForElement.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(by));
    
  2. 如果出现任何覆盖,请确保其关闭,因为它可能会阻碍元素获得点击

【讨论】:

  • 我试过了,是的,同样的错误。似乎另一个类获得了点击.. 有什么方法可以隐藏获得点击的类,如错误所述
  • 失败时能否提供html或分享截图?
  • 当我添加...... driver.findElement(By.partialLinkText("Add portfolio")).sendKeys(Keys.RETURN);
【解决方案2】:

这可能会对您有所帮助,但请确保窗口中没有活动的警报或弹出窗口。

 WebDriverWait wait = new WebDriverWait(driver,60);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_elm")));
     Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("xpath_of_elm"))).click().build().perform();

【讨论】:

    【解决方案3】:

    我建议你在这里使用 JavascriptExecutor 点击方法。

    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", element);
    

    如果这仍然不起作用,请检查屏幕上是否有任何加载图像;在这种情况下,您将需要等待该图像消失。

    【讨论】:

      猜你喜欢
      • 2018-03-16
      • 1970-01-01
      • 2016-06-08
      • 2016-12-19
      • 2017-04-16
      • 2017-04-13
      • 2021-10-08
      • 2015-01-12
      • 1970-01-01
      相关资源
      最近更新 更多