我目前正在尝试自动化登录流程。快乐路径的编码工作正常。我现在正在针对无效凭据进行编码。
我的代码看起来与此类似:
driver.findElement(By.xpath("//android.widget.Button[@text='Password']").click;
//At this point the button is pressed
Thread.sleep(10000); //Screen with the following item is definitely visible
MobileElement actual = (MobileElement)(new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.view.View[@content-desc='Invalid user ID or password. Try again']"))));
//Note when I print out the xml and use xpathfinder I get 1 response
我收到这样的回复:
Am element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
最佳答案
您可以尝试流畅的等待而不是正常的网络驱动程序等待
public void waitForElement(final By by,
int timeInSeconds,WebDriver driver) {
Wait<WebDriver> wait = FluentWait<WebDriver>(driver)
.withTimeout(timeInSeconds, TimeUnit.SECONDS)
.pollingEvery(500, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
wait.until(new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
List<WebElement> elements = driver.findElements(by);
if (elements.size() > 0) {
return true;
}
}
return false;
}
});
}
然后调用电话
waitForElement(By.xpath("//android.view.View[@content-desc='Invalid user ID or password. Try again']", 60,driver)
关于java - Appium:找不到可见的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38963282/