答案 0 :(得分:0)
您可以检查与id / class匹配的元素数,然后仅在至少有1个元素时单击。
List<WebElement> elements = driver.findElements(By.id("com.simplemobiletools.gallery:id/parentPanel"));
if (elements.size()>0){
elements.get(0).click();
}
答案 1 :(得分:0)
//You can change ExpectedConditions type (visibilityOfElementLocated)
public boolean isExist(By elementBy, int seconds) {
try {
WebDriverWait wait = new WebDriverWait(driver, seconds);
wait.until(ExpectedConditions.presenceOfElementLocated(elementBy));
return true;
} catch (Exception e) {
return false;
}
}
//if popup is displayed within 3 seconds
By POPUP = By.id("com.simplemobiletools.gallery:id/parentPanel");
if (isExist(POPUP, 3)) {
//do something - for example click cancel button
}