【问题标题】:Visible but overlaid可见但覆盖
【发布时间】:2017-11-19 22:15:27
【问题描述】:

我正在使用 selenium 制作一个脚本,它会在网页中心显示加载图标。执行第一行后会出现加载图标

test.driver.findElement(By.id("oaapprove")).click();
test.driver.findElement(By.xpath("//*[text()='DATA EXPLORER']")).click();

第二个元素仍然存在于 DOM 中,但它不可点击,所以我收到错误,因为不可点击

我试过这个:

Boolean isPresent=test.driver.findElements(By.xpath("//div[@class='spinner-container']")).size() > 0;
    if(isPresent)
    {
        System.out.println("Target element found");
    }
    while(test.driver.findElements(By.xpath("//div[@class='spinner-container']")).size() > 0)
    {
        try {
            System.out.println("inside");
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    if(!(test.driver.findElements(By.xpath("//div[@class='spinner-container']")).size() > 0))
    {
        System.out.println("Target element not found");
    }

它正在打印“内部”,直到加载图标可见,但在图标消失后它不会打印“内部”,而是等待 7-8 秒,然后执行下一条语句。 等待的原因是什么?

你能告诉我如何解决这个问题。

【问题讨论】:

  • 您的解决方案正在运行,但即使在加载图标消失后它仍在等待。
  • 这可能意味着您错误地定义了带有加载图标的模态
  • 其中的论点 10 是什么?
  • 这是超时。如果等待超过 10 秒,则会出现超时异常

标签: java selenium xpath web-scraping wait


【解决方案1】:

如果使用 fluentwait 显示该元素是可点击的,请尝试操作类:

WebElement yourElement = test.driver.findElement(By.xpath("//*[text()='DATA EXPLORER']"));

Actions act = new  Actions(test.driver);
act.moveToElement(yourElement).click().build().perform();

【讨论】:

  • 但它应该等到加载图标消失
  • 是的,但是你说在执行 test.driver.findElement(By.id("oaapprove")).click();加载图标熄灭
【解决方案2】:

我得到了解决方案,我使用了stalenessOf

new WebDriverWait(driver, 10).until(ExpectedConditions.stalenessOf(findElement(By.xpath("element_path"))));

【讨论】:

    猜你喜欢
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-01
    • 2011-02-01
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    相关资源
    最近更新 更多