I'm using Appium .NET driver to write some automated tests for one Android app.
I need to add a wait to find one element as it takes some time to load.
If I use Thread.Sleep
it works fine but it nasty way so thought to check with WebDriverWait
but using WebDriverWait
the test failed and not able to find the element.
Working code:
[TestMethod]
public void TestMethod1()
{
Thread.Sleep(TimeSpan.FromSeconds(10));
IWebElement obj = driver.FindElementByXPath("//android.widget.Button[@text='Get Started']");
obj.Click();
}
Not working:
[TestMethod]
public void TestMethod1()
{
var obj = driver.FindElement(By.XPath("//android.widget.Button[@text='Get Started']"), 15);
obj.Click();
}
FindElement
is the extension method written by Loudenvier here
Log: Here is my Appium log from thread sleep and webdriverwait approach. Appreciate your help.
Edit1: the button element I'm trying to find is part of a Android DialogFragment. This DialogFragment comes up when user open the the app for first time, this is a kind of welcome screen.
What I noticed WebDriverWait
actually wait in the primary app fragment and trying to search for the element and it fails. But Thread.Sleep
works because in that case the DialogFragment
get loaded on top of the primary app fragment and then webdriver search the element in the correct fragment. I tried with the ImplicitlyWait
and explicitwait
but result is same.
Is there any better way to wait for DialogFragment?