In the Java Selenium Framework, is it possible for a FluentWait to check for two different expected conditions? Where it could be either one or the other.
To give more context, I need to check a website's title, but depending on the circumstances it could redirect to one of two sites (imagine you fail to log in and are sent to a log in page, but if you do log in you're redirected to the homepage).
Would an Implicit Wait be better for this case? Because the site seems to load rather slowly a lot of times and I'm forced to continuously increase the wait time on it.
You may manipulate ExpectedConditions to form a suitable complex condition. There're or(...) and urlContains(...) methods useful for your needs. Something like this:
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.or(
ExpectedConditions.urlContains("http://first.si.te/url"),
ExpectedConditions.urlContains("http://second.si.te/url")
));
You can create you own waiting condition with a lambda expression. This example waits until the title starts with "abcd" or contains "1234":
WebDriverWait wait = new WebDriverWait(driver, 20);
String page_title = wait.until((WebDriver wd)->{
String title = wd.getTitle();
return title.startsWith("abcd") || title.contains("1234") ? title : null;
});
System.out.println("Page title is: " + page_title);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With