提问者:小点点

如何使用WebDriver检查元素是否可见-永恒加载


我正在测试一个关闭窗口的按钮。然后当我单击按钮时,我需要检查窗口是否关闭。

我创建了这个方法:

enter code here




public boolean isElementPresent(String locatorKey) {
    try {
        driver.findElement(By.xpath(locatorKey));
        return true;
    } catch (org.openqa.selenium.NoSuchElementException e) {
        Assert.assertFalse((isElementPresent(String.valueOf(By.xpath(locatorKey)))));
        return false;
    }
}





enter code here

但是它不起作用。硒在加载最后一步时停留了很长时间,最终显示了这个错误

命令:[8139ce6f8c35642a752d7fbedb186ec6,findElement{using=xpath,value=By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:By.xpath:


共1个答案

匿名用户

如果您使用Java,请考虑使用Selenide。

$x("your xpath").should(disappear);

这就是你需要用硒做的一切。

https://selenide.org/