Search code examples
androidseleniumc#-4.0appium

Find and element on Android using Selenium and Appium


I'm using this code in order to find an element on my Android (Native App) device using selenium and Appium :

var wait = new WebDriverWait(_driver,TimeSpan.FromSeconds(15));
var phone = wait.Until(x => x.FindElements(By.Id("foo")));

The problem is that Selenium finds the element only seemingly. Meaning it finds it, but with no attributes at all.

But when using :

System.Threading.Thread.Sleep(5000)

everything works like a charm.

I have tried to increase the seconds in the driver's wait, but it didn't help.


Solution

  • I think the element is not getting loaded at the time script is performing an operation on it. Try to add a visibility check before performing any operation on that element

    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.locator);