java - Appium:找不到可见的元素

标签 java android appium

我目前正在尝试自动化登录流程。快乐路径的编码工作正常。我现在正在针对无效凭据进行编码。

我的代码看起来与此类似:

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/

相关文章:

android - Appium 显示错误“未知错误 : Chrome version must be >= 31. 0.1650.59\n 即使 Android 移动应用程序中的 chrome 版本更高

python - 无法解决 'No module named Appium' 错误

java - Tomcat启动时实例化对象

java - Firestore 好友列表未显示正确的方式

android - 获取可写数据库时 Android 中的 NullPointerException

android - 致命异常 : Thread-18 java. lang.OutOfMemoryError:在使用较低版本设备的 android volley 中

Appium 无法使用 UiSelector 在屏幕外定位元素

java - 如何从 Intstream 创建 ArrayList

c# - 在 Java/C# 中调用同一对象的多个方法的编码标准

android - 如何在 Android 中为按钮启用音效