WebDriverWait wait = new WebDriverWait(driver, 60)
WebElement element = driver.findElement(By.xpath("//div[contains(text(),'Loading...')]"));
System.out.println("Test");
wait.until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(),'Loading...')]"))));
System.out.println("Test");
正在尝试等待页面加载完成。第一个“测试”打印在控制台中,下面的异常打印在执行 wait.until 语句时。 即使在加载屏幕消失后,wait.until 仍在等待。 已经尝试过元素的陈旧性也不起作用,得到相同的超时异常。 加载完成后,该元素在 DOM 中不再可用
最佳答案
当您想等待元素不存在时,请使用 presenceOfAllElementsLocatedBy
而不是 presenceOfElementLocated
:
wait.until(ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[contains(text(),'Loading...')]"))));
它将一直等到页面上没有适合定位器的元素。
关于java - Selenium Webdriver "Expectedconditions.not"未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19930703/