I want use wait.until(ExpectedConditions)
with TWO elements.
I am running a test, and I need WebDriver
to wait until either of Element1 OR Element2 shows up. Then I need to pick whoever shows up first. I've tried:
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@class='....']"))) || wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h3[@class='... ']")));
// Then I would need:
String result = driver.findElement(By.xpath("...")).getText() || driver.findElement(By.xpath("...")).getText();
To sum up, I need to wait until either of the TWO elements shows up. Then pick whoever shows up (they cannot show up simultaneously) Please Help.
You can also use a CSSSelector like this:
Replace someClass and otherClass with what you had in [...] in the xpath.
I think that your problem has a simple solution if you put "OR" into xpath.
Then, to print the result use for example:
Unfortunately, there is no such a command. You can overcome this by try and catch, or I would better recommend you to use open source Ruby library Watir.
Now there's a native solution for that, the
or
method, check the doc.You use it like so:
There is an alternative way to wait but it isnt using expected conditions and it uses a lambda expression instead..
This is the method I declared in my Helper class, it works like a charm. Just create your own
ExpectedCondition
and make it return any of elements found by locators:And then you can use it this way:
Here
SERVICE_TITLE_LOCATOR
andATTENTION_REQUEST_ALREADY_PRESENTS_WINDOW_LOCATOR
are two static locators for page.