等到方法超时后不抛出异常

Wait until method does not throw exception after timeout

我正在像这样使用 Appium 显式等待 android 应用程序自动化:

WebDriverWait wait = new WebDriverWait(driver,15);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(idPrefix + buttonId)));

但由于某种原因,15 秒后没有抛出异常,测试 运行 基本上仍然卡在等待元素。

appium 日志有时会打印 [base driver] Waiting up to 5000000 ms for condition 但我真的不知道这个数字是从哪里来的。

我正在使用 appium 服务器 v1.13.0 和 caps.setCapability(“automationName”, “UiAutomator2"); for android

非常感谢任何帮助

首先,你不需要设置“UiAutomator2”能力,它已经是appium 1.13.0的默认值。 我快速搜索了如此巨大的超时值,但实际上什么也没找到。 初始化 AndroidDriver 时是否设置了 implicitlyWait() 参数? 如果您提供部分代码,这将非常有帮助。 如果您不想在没有元素时抛出异常,请尝试使用这种方法来检查元素是否存在:

driver.findElementsById(yourId).isEmpty();

它会 return true 或 false 并且不会有 NoSuchElementException 这非常方便。 注意:注意方法名,不是findElementById(),是findElementsById();

看来您可能设置了 5000 秒的隐式等待时间。

在您的代码中的某处查找此配置集:

driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);