Appium_ios_android
Appium_ios_android

Reputation: 21

FluentWait with findElementByAndroidUIAutomator

I'm automating a native android app using Appium and trying to use FluentWait to wait for a page/element to show up using the following snippet:

@Test
public static void Test1() {
    MobileElement mobileElement = func(getdriver());
    System.out.println(mobileElement.getText());
}

private static MobileElement func(AppiumDriver driver) {
    AndroidDriver and = (AndroidDriver) getdriver();
    String value1 = "More";
    String value2 = "new UiSelector().text(" + "\"" + value1 + "\"" + ")";

    FluentWait<AndroidDriver> wait = new FluentWait(and)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(1, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class)
            .ignoring(TimeoutException.class);

    MobileElement myElement = wait.until(new Function<AndroidDriver, MobileElement>() {
        @Override
        public MobileElement apply(AndroidDriver androidDriver) {
            return (MobileElement) androidDriver.findElementByAndroidUIAutomator(value2);
        }
    });
    return myElement;
}

I'm trying to wait (max of 30 secs) for the More page to show up after successful login. The problem I'm seeing is the inline method returns immediately with "An element could not be located on the page using the given search parameters". I would like FluentWait to keep polling for the myElement to appear on the screen while ignoring "NoSuchElementException". It is not happening.

What I'm doing incorrectly here?

Please advise.

Upvotes: 0

Views: 2214

Answers (1)

krishna chetan
krishna chetan

Reputation: 659

I use python and the following code works fine, you can use self.driver.implicitly_wait(10,5) or any value

        self.driver.find_element_by_name('NEXT').click()
        self.driver.implicitly_wait(10)
        self.driver.find_element_by_id('com.sndfbi.android:id/m_passwordTextField').send_keys('1111abcd')
        self.driver.find_element_by_id('com.bdhasb.android:id/m_passwordConfirmTextField').send_keys('1111abcd')
        self.driver.find_element_by_name('SAVE').click()
        self.driver.implicitly_wait(10)
        self.driver.find_element_by_name('OK').click()
        self.driver.implicitly_wait(10)
        self.driver.back()

Upvotes: 1

Related Questions