I have seen this question, which is a combination of wait + findElementBy
.
But, my question is slightly different, since i need to check for URL (rather than element) after page loaded completely.
I already tried the below solution but it is not working for me:
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));
}
And here is my selenium version:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
Update: Thanks to @Guy when i use the below method:
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));
}
It complains with:
The method until(Function<WebDriver,T>) in the type WebDriverWait is not applicable for the arguments ()
Here is the repository.
I updated the selnium to 3.14.0
since 3.142.6
does not work for me.