【问题标题】:Appium: Cannot find an element that is visibleAppium:找不到可见的元素
【发布时间】:2016-09-17 07:37:52
【问题描述】:

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

我的代码如下所示:

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)

【问题讨论】:

    标签: java android appium


    【解决方案1】:

    你可以试试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;
                }
            });
        }
    

    然后拨打电话

    waitForElement(By.xpath("//android.view.View[@content-desc='Invalid user ID or password. Try again']", 60,driver)
    

    【讨论】:

    • 感谢您的评论,我一定会在不同的测试用例上进行尝试。当我使用getAttribute("content-desc") 时,这是一个问题。一旦我将属性更改为命名它就起作用了。当检查员告诉我使用“content-desc”时,我很奇怪
    【解决方案2】:

    所以问题是 getAttribute("content-desc") 不是 appium 正在寻找的。而使用 getAttribute("name") 将返回所需的值(又名 content-desc)。

    【讨论】:

      猜你喜欢
      • 2020-08-11
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 2018-11-16
      • 2019-10-06
      • 1970-01-01
      • 2021-10-25
      • 2016-12-09
      相关资源
      最近更新 更多