我创建了一些代码来在滑动操作后查找 AccessibilityId,但它“没有”进入我的 while 条件。 如何设置条件来查找AccessibilityId?
这就是我想要的场景。
1.Launch app, there is no test1_action buttons (AccessibilityId = test1_action)
2.To Click test1_action, will repeat swipe "i" times till find AccessibilityId.
3.After "i" times swiping, if there will be test1_action button then it will click it
iOS/iPhone/Appium
WebDriverWait wait = new WebDriverWait(driver, 20);
int i = 0;
while
(!driver.findElement(MobileBy.AccessibilityId("test1_action")).isDisplayed()) {
swipe(331, 544, 50, 544, 2);
i++;
}
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("test1_action"))).click();
当我运行这个时,我遇到了以下错误
Caused by: org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
最佳答案
如果该元素不存在,您将得到 NoSuchElementException尝试调用 isDisplayed()函数,考虑修改您的代码,如下所示:
while (driver.findElements(MobileBy.AccessibilityId("test1_action")).size() == 0 && i < 100) {
swipe(331, 544, 50, 544, 2);
i++;
}
您还可以考虑使用SwipeWhileNotFound方法。
关于java - 如何设置条件来查找 AccessibilityId?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56783657/