selenium webdriver – Waiting for one element or another in Selenide
In Selenide, you can use the $$ method to find multiple elements and the waitUntil method to wait for any one of them to be present. Here’s an example of how you can wait for either one of two elements in Selenide:
import static com.codeborne.selenide.Condition.*;
import static com.codeborne.selenide.Selenide.*;
public void waitForOneorOtherElement(SelenideElement element1, SelenideElement element2) {
$$x(element1.getXPath() + "|" + element2.getXPath())
.shouldHaveSize(1)
.waitUntil(visible, defaultWait);
}
In this example, we use the $$x method to find elements using XPath, and concatenate the XPaths of both elements using the | operator to find either one of them. The resulting list of elements should have a size of 1, which means either one of the elements is present. Then we use the waitUntil method to wait for that element to become visible, with a timeout of defaultWait (which you can define as a constant).
Note that you can replace the $$x method with any other method that returns a list of elements in Selenide, such as $$ (for CSS selectors) or findAll (for Selenide conditions).
I hope this helps! For more information, you can refer to the Selenide documentation on finding elements and waiting for conditions to be met.
Read more here: Source link
