Wait for element to disappear/ not be preset anymore

Hello,

I’m trying to find a solution to wait for an element to not be visible anymore,I have a progress bar when I’m entering in a new screen and I don’t know exactly how much will take for the progress bar to disappear.
I’m trying to tell appium to wait until the element is not visible and them continue with the test.
Here are my samples:
1st:
FluentWait wait = new WebDriverWait(driver)
.pollingEvery(500, TimeUnit.MILLISECONDS)
.withTimeout(15, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.invisibilityOf(myElement));

2nd:
public boolean isElementNotPresent() {
try {
WebDriverWait wait = new WebDriverWait(driver, 20, 500);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id(“progress_bar”)));
return false;
} catch (NoSuchElementException e) {
return true;
}

I tried with almost all method of the ExpectedConditions which would be suitable but nothing.

Config
Java client: 5.0.4 (tried with last version also)
Appium Server Version :1.7.2
Selenium-Java Version 3.11

The problem is that sometimes, if the driver sincronize with the progress bar, it will spot that is no longer visible and continue with the test.
But most of the times, the bar is no longer visible and the driver keeps searching for it and say that no element found.

If someone would have any solution for this I would appreciate.

Thank you

I recommend you update Java client to the latest BETA version and try implementing with “FakeElement” as explained in this example below:

If built in functions not doing the job for u then make your own this one’s just a work around i wont recommend. If it suits your requirement then give a try or else look for some other option better.

@FindBy(id=“Progress bar id”)
public List Element_name;

// Its best to make this a func if you wana reuse on every screen pass the webelement to the func and look for the elements size or else one time like below.
long endTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(1L, TimeUnit.MINUTES); // Put standard timeout of your app.
while(Element_name.size()>0 && System.nanoTime() < endTime){
Thread.sleep(1000);
}

// TODO: Do the rest of the operation.

Hi,
I saw this example on github, since i’m watching the thread.
I’m using the latest java version 6.0.0-Beta5
Unfortunately I’m not able to implement it and make it work in my code(I started the Appium and Java journey 2 month ago).

If you have it already implement it might be great to share it.

Thanks

Hi,

Not working for me, I get No element found, when the bar is no longer visible.

Thanks

Anybody any ideas? I’m really stuck into this.

I am using AndroidDriver, I was thinking maybe I should switch to AppiumDriver?
Would this help?

public AndroidDriver getDriver() throws MalformedURLException {
serverUrl = new URL(“http://localhost:” + APPIUM_PORT + “/wd/hub”);
driver = new AndroidDriver(serverUrl, capabilities);
driver.manage().timeouts().implicitlyWait(IMPLICIT_WAIT_TIME, TimeUnit.SECONDS);
return driver;

I use python client for very similar use case and I am able to do it successfully with following code

def wait_until_element_is_invisible(driver, find_by, wait_until=10):
return WebDriverWait(driver, wait_until).until(EC.invisibility_of_element_located(find_by))

I solved the issue. The problem was that i was using uiAutomator instead of uiAutomator2.
Works Ok with Java client 7.0 and Appium 1.10.1

public boolean isElementNotPresent() {
try {
WebDriverWait wait = new WebDriverWait(driver, 20, 500);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id(“progress_bar”)));
return false;
} catch (NoSuchElementException e) {
return true;
}