Any better way to wait till elemant presant

In Appium i was using thread.sleep() most of the time as a solution to handle the wait for perform the next task.
But is there any better way to do the same thing without using thread.sleep().

I tired with

WebDriverWait wait = new WebDriverWait(WebDriverInti.driver, TimeSpan.FromSeconds(5000));
wait.Until(ExpectedConditions.ElementExists(By.XPath("//*[@id=“rdiv”/h3/a")));

But no luck :frowning:

The line to create a wait should look something like this:

WebDriverWait wait = new WebDriverWait(driver,60);

where 60 is duration in seconds and driver is the AindroidDriver / IOSDriver you declared.
If you want to use id with xpath, your xpath should be:

"//*[@resource-id='elementid']"

Where elementid is the full id that appears next to resource-id in UI Automator viewer

1 Like

Hi,

You can try

WebDriverWait wait = new WebDriverWait(driver, time);
wait.until(ExpectedConditions.visibilityOf(WebElement element));

  1. In your case xpath should be written as @Alexis was mentioned. And if you’ve resourceId, then please go with driver.findElementById(“xyz”); it will take less time to identify.
  2. Or you can put implicit wait at the begining.

Regards,
Bhaskar.