2016-08-15 291 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