Manisha
Manisha

Reputation: 1

explicit wait for webdriver is not working in appium 1.7.2

I have created a utility class where I have:

public void waitForScreenToLoad(AndroidDriver  lDriver, WebElement element, int seconds){
    WebDriverWait wait = new WebDriverWait(lDriver,seconds);
    wait.until(ExpectedConditions.visibilityOf(element));
}

and my main class of sign in has:

@Test (priority = 0)
public void SignIn() throws InterruptedException, IOException {
    Thread.sleep(8000);
    MobileElement ele = (MobileElement) driver.findElementByAccessibilityId("abcde");
    MobileElement sign = (MobileElement) driver.findElementByAccessibilityId("Sign in");
    sign.click();
    // Thread.sleep(8000);
    waitForScreenToLoad(driver, ele, 120);
    captureScreenshot(driver,folder_name,df);   
    Thread.sleep(2000);
}

They are both in the same package. Element ele is present on both pages before and after sign in. The wait does not work but, if I use Thread.sleep it works and I am able to take a screenshot.

Can anybody tell me what is wrong with my code? or if using Thread.sleep so frequently is ok to make it work?

Upvotes: 0

Views: 1175

Answers (1)

Alexey Dolgopolov
Alexey Dolgopolov

Reputation: 700

ele has become stale after clicking and reloading page. Try to use another expected condition.

public void waitForScreenToLoad(AndroidDriver  lDriver, By locator, int seconds)
        {

                WebDriverWait wait = new WebDriverWait(lDriver,seconds);
                wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
          }


@Test (priority = 0)
  public void SignIn() throws InterruptedException, IOException {
            Thread.sleep(8000);
            //MobileElement ele = (MobileElement) driver.findElementByAccessibilityId("abcde");
            By ele_locator = By.AccessibilityId("abcde");
            MobileElement sign = (MobileElement) driver.findElementByAccessibilityId("Sign in");
            sign.click();
           // Thread.sleep(8000);
            waitForScreenToLoad(driver, ele_locator, 120);
            captureScreenshot(driver,folder_name,df);   
            Thread.sleep(2000);

Upvotes: 1

Related Questions