Java Appium:找不到可见的元素

Java Appium:找不到可见的元素,java,android,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 Mobile

我目前正在尝试自动登录流。快乐路径的编码工作正常。我现在正在编写无效凭据的代码

我的代码与此类似:

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)

您可以尝试使用fluent wait,而不是普通的webdriver wait

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;
            }
        });
    }

您可以尝试使用fluent wait,而不是普通的webdriver wait

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;
            }
        });
    }

所以问题在于,
getAttribute(“content desc”)
不是appium所要寻找的。相反,使用
getAttribute(“name”)
将返回所需的值(也称为content desc)。

因此问题在于
getAttribute(“content desc”)
不是appium所要的。相反,使用
getAttribute(“name”)
将返回所需的值(也称为content desc)。

谢谢您的评论,我一定会在不同的测试用例上尝试。事实证明,当我使用
getAttribute(“content desc”)
时,这是一个问题。只要我把属性改为name,它就工作了。我很奇怪,因为检查员告诉我使用“contentdesc”,谢谢你的评论,我一定会在不同的测试用例上尝试。事实证明,当我使用
getAttribute(“content desc”)
时,这是一个问题。只要我把属性改为name,它就工作了。当检查员告诉我使用“内容描述”时,我很奇怪