java - 如何处理 <div id ="preloader"> 用 Selenium 模糊其他元素,检查其他答案没有任何帮助

标签 java selenium testng

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

我尝试了所有的等待,显式等待 20 秒似乎有效,但通常也会失败。另外,这种情况发生在应用程序上的几乎每个元素之前,我认为在每个元素之前应用显式 wait 或 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

最佳答案

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

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")));
}

关于java - 如何处理 <div id ="preloader"> 用 Selenium 模糊其他元素,检查其他答案没有任何帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57809310/

相关文章:

java - 带有 break 语句的无限 while 循环

python - 无法访问表单字段

java - 为什么 TestNG 允许几个预期的异常?

selenium - 在 selenium webdriver 中将 xpath 转换为 css 无法正常工作?

java - 如何从命令行运行具有多个包的 Selenium testNG 文件?

java - 有没有一种方法可以从不同的包(或类)运行一个定义的和 X 个随机 TestNG 测试?

java - 无法从 List<Object> 获取属性 - Servlet

独立类的 Java ActionListener

java - WebView.Destroy() 导致致命信号 11 崩溃

java - Selenium 测试卡住并且未运行