【问题标题】:how to handle <div id="preloader"> obscuring other elements with selenium, checked other answers nothing helped [duplicate]如何处理 <div id="preloader"> 用硒掩盖其他元素,检查其他答案没有任何帮助[重复]
【发布时间】:2020-01-08 13:58:09
【问题描述】:

我正在尝试使用 selenium java 自动化 Web 应用程序,这是我不断收到的消息 org.openqa.selenium.ElementClickInterceptedException: Element is not clickable at point (85,37) because another element obscured it in all the浏览器。

我尝试了所有的等待,显式等待 20 秒似乎有效,但通常也失败了。此外,这几乎发生在应用程序上的每个元素之前,我认为在每个元素之前应用显式等待或 Thread.sleep 是一个好习惯。

    driver.findElement(By.xpath("//span[contains(text(),'Agent Corrections')]")).click();

    WebDriverWait wait1 = new WebDriverWait(driver, 20);
    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));

    String expectedText = "";
    String actualText = driver.findElement(By.cssSelector("#users_management > div.panel-heading > h4")).getText();
    Assert.assertEquals(expectedText, actualText);

    driver.findElement(By.xpath("//span[contains(text(),'')]")).click();

    driver.findElement(By.xpath("//span[contains(text(),'')]")).click();

    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));
    driver.findElement(By.id("pcc")).sendKeys("");
    driver.findElement(By.id("pnr")).sendKeys("");
    driver.findElement(By.id("FFFormSubmit")).click();

    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));

元素遮挡是用 div id = preloader

【问题讨论】:

  • 我们可以获取页面 URL 吗?
  • 您还可以在使用单个元素之前检查它们是否可见/可点击/可交互。这将代替检查是否没有覆盖
  • 不幸的是我不能给你页面 URL 因为它在组织之下。但是,当我在显式等待中使用其他任何东西而不是“元素的不可见性”时,它会失败。也可能是网络应用不稳定的问题。
  • 20+ 秒等待每个元素听起来像是一个严重的问题。您要上传大文件吗?
  • 不,没有文件。另外,我与一位开发人员交谈过,他说这个问题是因为他的代码是后端而我的脚本是前端而忽略了这个问题。搜索了很多,但找不到解决方案。

标签: java selenium testng


【解决方案1】:

我会先检查预加载器是否显示,然后等待它不可见。这可能会使执行速度变慢,但它是故障安全的。

driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS) // this will make wait time of 5 seconds for each element including preloader.

WebDriverWait wait1 = new WebDriverWait(driver, 20);
 if(driver.findElement(By.id("preloader")).isDisplayed())
{    wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.id("preloader")));
}

【讨论】:

  • 我以前尝试过这种技术,但它不是安全的。随着时间的推移,您可能永远不会发现它显示出来,然后它就会中断。
  • 是的。这取决于应用程序,可能需要调整等待时间。
  • 这比我的方法工作得更快,但问题是页面加载时每个元素之前都会出现异常。并且 Thread.sleep 不是在每个元素之前应用的好方法,因为如果我有一个更大的测试脚本,它需要很长时间才能完成。
  • 您不应将隐式等待与显式等待混为一谈。
猜你喜欢
  • 2013-10-19
  • 2011-10-27
  • 1970-01-01
  • 1970-01-01
  • 2012-08-17
  • 1970-01-01
  • 2020-05-30
  • 1970-01-01
相关资源
最近更新 更多