我目前正在尝试自动执行登录流程。快乐路径的编码可以正常工作。我现在正在编码无效的凭证。

我的代码与此类似:

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)

最佳答案

您可以尝试流畅的等待,而不是普通的webdriver等待

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)

07-26 06:28
查看更多