Java 如果出现元素,如何关闭?
如果此元素在运行时出现,我将使用什么命令来关闭它。我希望我的代码能够注意到它何时出现,但是,如果它没有出现,则继续使用常规优先级Java 如果出现元素,如何关闭?,java,eclipse,selenium,automation,appium,Java,Eclipse,Selenium,Automation,Appium,如果此元素在运行时出现,我将使用什么命令来关闭它。我希望我的代码能够注意到它何时出现,但是,如果它没有出现,则继续使用常规优先级 您可以检查与id/类匹配的元素数量,然后仅在至少有1个元素时单击 List<WebElement> elements = driver.findElements(By.id("com.simplemobiletools.gallery:id/parentPanel")); if (elements.size()>0){ elements.ge
您可以检查与id/类匹配的元素数量,然后仅在至少有1个元素时单击
List<WebElement> elements = driver.findElements(By.id("com.simplemobiletools.gallery:id/parentPanel"));
if (elements.size()>0){
elements.get(0).click();
}
List elements=driver.findElements(By.id(“com.simplemobiletools.gallery:id/parentPanel”);
if(elements.size()>0){
元素。获取(0)。单击();
}
你能分享HTML代码吗?我在用android
//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
}