wait.until(ExpectedConditions.visibilityOf Element1 OR Element2)

后端 未结 8 1143
遇见更好的自我
遇见更好的自我 2020-12-14 12:30

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

8条回答
  •  不知归路
    2020-12-14 13:05

    I think that your problem has a simple solution if you put "OR" into xpath.

    WebDriverWait wait = new WebDriverWait(driver, 60); 
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h2[@class='....'] | //h3[@class='... ']"))); 
    

    Then, to print the result use for example:

    if(driver.findElements(By.xpath("//h2[@class='....']")).size()>0){
           driver.findElement(By.xpath("//h2[@class='....']")).getText();
    }else{
           driver.findElement(By.xpath("//h3[@class='....']")).getText();
    }
    

提交回复
热议问题