Selenium two expected conditions with one timeout counter

209 Views Asked by At

I wonder if there is a way to use selenium expected conditions where there are two code scenarios for two expected conditions and only one time period to wait (same timeout counter exception); I mean:

  • if expected condition 1 ---> code scenario 1;
  • if expected condition 2 ---> code scenario 2;
  • else if timeout(20) ---> Exception code scenario.

My code:

try {
    new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.elementToBeClickable(By.name("AAA")));
    then my scenario 1 code for execution;
catch(TimeoutException e) {
    System.out.println("Time out!");
}
try {
    new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.elementToBeClickable(By.name("BBB")));
    then my scenario 2 code for execution;
catch(TimeoutException e) {
    System.out.println(Time out!");
}
0

There are 0 best solutions below