使用findElementByAndroidUIAutomator的java FluentWait
我正在使用Appium自动化一个本机安卓应用程序,并尝试使用FluentWait等待页面/元素显示,使用以下代码片段:
@Test
public static void Test1() {
MobileElement mobileElement = func(getdriver());
System.out.println(mobileElement.getText());
}
private static MobileElement func(AppiumDriver driver) {
AndroidDriver and = (AndroidDriver) getdriver();
String value1 = "More";
String value2 = "new UiSelector().text(" + "\"" + value1 + "\"" + ")";
FluentWait<AndroidDriver> wait = new FluentWait(and)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
MobileElement myElement = wait.until(new Function<AndroidDriver, MobileElement>() {
@Override
public MobileElement apply(AndroidDriver 安卓Driver) {
return (MobileElement) 安卓Driver.findElementByAndroidUIAutomator(value2);
}
});
return myElement;
}
我正在尝试等待(最多30秒),等待更多页面在成功登录后显示。我看到的问题是内联方法立即返回“使用给定的搜索参数无法在页面上找到元素”。我希望FluentWait在忽略“NoTouchElementException”的同时,继续轮询myElement是否出现在屏幕上。它没有发生
我做错了什么
请告知
# 1 楼答案
我使用python,下面的代码运行良好,您可以使用self。驾驶员隐式地等待(10,5)或任何值