2016-08-15 238 views
1

我目前正在尝试自动化登录流。幸福路径的编码正常工作。我现在正在编码无效凭证。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) 

回答

0

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

0

你可以尝试一口流利的等待,而不是正常的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) 
+0

感谢您的评论,我一定会尝试在不同的测试案例。当我使用'getAttribute(“content-desc”)'时发现这是一个问题。只要我将属性更改为名称就行了。当检查员告诉我使用“content-desc”时,我很奇怪, – JaysonP