0

アイテムを検索しようとしていますが、見つかった場合は特定の要素に表示され、見つからない場合は別の要素が表示されるため、以下のような予想される条件でORを使用しようとしました:

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

どの要素が SearchResult または SearchgetData に表示されるかを知る方法があるかどうか知りたい

4

1 に答える 1

1

これらの要素のリストをフェッチし、要素リストのサイズがゼロより大きい場合、その要素がページに存在するため、リストがゼロより大きいサイズを確認できます。

次のようにできます。

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
}
于 2020-04-12T17:57:46.233 に答える