Selenium ExpectedConditions With Logical Operators - Codoid
Select Page
Selenium

Selenium ExpectedConditions With Logical Operators

How to wait until at least one element is clickable in a group of web elements?

Selenium ExpectedConditions With Logical Operators

How to check or wait until multiple web elements are visible in one webdriver ExpectedCondition? Or how to wait until at least one element is clickable in a group of web elements?

Selenium WebDriver ExpectedCondition supports logical operators which has answers for the above questions and it also helps to create robust automation test scripts. Let’s see ExpectedConditions’ logical operators with examples.

AND Operator

//Wait until both the elements are visible
wait.until(
              ExpectedConditions.and(
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Services")),
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Products"))
              )
          );
  

OR Operator

//Wait until at least anyone condition returns true
wait.until(
              ExpectedConditions.or(
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Services")),
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Products"))
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Contact Us"))
              )
          );
  

Written By

Submit a Comment

Your email address will not be published. Required fields are marked *


How to check or wait until multiple web elements are visible in one webdriver ExpectedCondition? Or how to wait until at least one element is clickable in a group of web elements?

Selenium WebDriver ExpectedCondition supports logical operators which has answers for the above questions and it also helps to create robust automation test scripts. Let’s see ExpectedConditions’ logical operators with examples.

AND Operator

//Wait until both the elements are visible
wait.until(
              ExpectedConditions.and(
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Services")),
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Products"))
              )
          );
  

OR Operator

//Wait until at least anyone condition returns true
wait.until(
              ExpectedConditions.or(
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Services")),
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Products"))
                   ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("Contact Us"))
              )
          );