我正在编写针对Android和ioS运行的Appium测试。当我尝试查找不可见的MobileElement时,超时时间超过指定时间。如果我使用By.id,则超时是正确的。
45秒后超时
@AndroidFindBy(id = "ok_button")
private MobileElement okButton;
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(okButton));
5秒后超时
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.id("ok_button")));
答案 0 :(得分:0)
在页面对象构造函数中尝试:
PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this);
答案 1 :(得分:0)
在我看来,检查元素可用性和不可用性是最好的方法,而不是提及等待的TIMEOUT秒。(因为可能存在互联网速度问题!!)
public boolean isElementPresent(WebElement elementName, int timeout){
try{
WebDriverWait wait = new WebDriverWait(AppiumController.instance.driver, timeout);
wait.until(ExpectedConditions.visibilityOf(elementName));
return true;
}catch(Exception e){
return false;
}
}