Selenium 和 Java 中的预期条件 "OR"

expected conditions "OR" in Selenium and Java

我正在尝试搜索项目然后结果如果找到出现在特定元素中如果没有找到另一个元素将出现所以我尝试使用 OR 与预期条件如下:

              wait.until(ExpectedConditions.or(ExpectedConditions.visibilityOf(SearchResult),
            (ExpectedConditions.visibilityOf(SerachGetData))));

我想知道是否有办法知道哪个元素出现在 SearchResult 或 SearchgetData

您可以获取这些元素的列表,然后检查哪个列表的大小大于零,因为如果元素列表的大小大于零,那么该元素就会出现在页面上。

你可以这样做:

List<WebElement> elementList1 = driver.findElements(By.xpath("Add the xpath of first element here"));
List<WebElement> elementList2 = driver.findElements(By.xpath("Add the xpath of second element here"));

if(elementList1.size()>0){
    //Element 1 is present on the UI
} else if(elementList2.size()>0){
    //Element 2 is present on the UI
} else{
    //Both the elements are not present
}