简体   繁体   中英

Cannot locate an element using appium in ios

I am not able to locate an element despite the fact that using appium inspector the element is located using the same locator I use in code.

                By by = By.xpath("//UIATextView[@value='hey!!!!!']");
                boolean result;
                do{
                    device.swipeUp();
                     result = waitUntil(ExpectedConditions.visibilityOfElementLocated(by));
                }while (!result);

Where my waitUntil is defined as :

public boolean waitUntil(ExpectedCondition<WebElement> condition){ 
  WebDriverWait wait = new WebDriverWait(device.getDriverWrapper().getIosDriver(),5); 
  wait.withTimeout(1,TimeUnit.SECONDS); 
  try { 
    wait.until(condition); // i wait until the condition will be met (with a time out of 1 seconds) and return true 
    return true; 
  } 
  catch (Exception e) { 
    return false; // if after the timeout of 1 seconds has reached then i retrun false 
  } 
} 

I see that the device keeps swiping up although the element is presented. Any idea?

If you are looking forward to wait until an element is located on the screen, you can use something similar to the following snippet :

By by = By.xpath("//UIATextView[@value='hey!!!!!']"); //any locator strategy
new WebDriverWait(driver, timeToWaitInSeconds)
                .until(new ExpectedCondition<WebElement>() {
                    public WebElement apply(WebDriver d) {
                        return driver.findElement(by);
                    }
                });

OR something simpler like this shall also resolve things :

By by = By.xpath("//UIATextView[@value='hey!!!!!']");
result = driver.findElement(by);
boolean result;
while (!result){
   device.swipeUp();
   result = driver.findElement(by);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM