import org.openqa.selenium.NoSuchElementException;
public class Chazhaoyuansu {
/**
* 如果找到这个元素则继续执行下面的元素,找不则返回失败false,返回布尔值
* @param by
* @param waitTimes
* @return
*/
public static boolean whetherElementVisable(final By by, int waitTimes) {
for (int attempt = 0; attempt < waitTimes; attempt++) {
try {
return true;
} catch (NoSuchElementException e) {
if (attempt == waitTimes - 1) {
return false;
}
}
}
return false;
}
}
//如果有协议弹窗,则点击同意
if (Chazhaoyuansu.whetherElementVisable(By.id("com.cmcc.p.poc:id/tv_title"), 1)) {
//点击同意
androidDriver.findElementById("com.cmcc.p.poc:id/tv_confirm").click();
}else {
//点击不同意
androidDriver.findElementById("com.cmcc.p.poc:id/tv_cancel").click();
}