我见过这个问题,它是wait + findElementBy的组合。但是,我的问题略有不同,因为在页面完全加载之后,我需要检查(而不是元素)。
我已经尝试过以下解决方案,但是--它不适合我的:
public void checkCurrentURL(String expectedURL) {
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // 5 seconds delay to load the page
String realURL = driver.getCurrentUrl();
System.out.println("------------------------------------URL is: "+realURL);
Assert.assertTrue(realURL.equals(expectedURL));
}这是我的硒版本:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>更新:当我使用以下方法时,感谢@Guy::
public void checkCurrentURL(String expectedURL) {
new WebDriverWait(driver, 2).until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
return d.executeScript("return document.readyState").equals("complete");
}
}
);
String realURL = driver.getCurrentUrl();
System.out.println("------------------------------------URL is: "+realURL);
Assert.assertTrue(realURL.equals(expectedURL));
}它抱怨说:
The method until(Function<WebDriver,T>) in the type WebDriverWait is not applicable for the arguments ()这是存储库。
我将selnium更新为3.14.0,因为3.142.6对我不起作用。
发布于 2019-12-22 11:08:21
implicitlyWait用于配置搜索WebElement时的最大查找时间,这与此无关,从现在起将影响driver,而不仅仅是在方法范围内。
您可以使用WebDriverWait并检查document.readyState
new WebDriverWait(driver, pageLoadTimeout).until(
new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
return d.executeScript("return document.readyState").equals("complete");
}
}
);顺便说一句,3.4.0版已经相当老了(~2.5岁)。考虑更新版本3.142.6 (最新而不是alpha版本)。
https://stackoverflow.com/questions/59443603
复制相似问题