0

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?

Community
  • 1
  • 1
Pritam Karmakar
  • 2,773
  • 5
  • 30
  • 49

1 Answers1

0

Why not using explicit wait and wait for driver to find element? Plus, the find element mechanisms look different in your code above.

[TestMethod]
public void TestMethod1()
{
  By byXpath = By.XPath("//android.widget.Button[@text='Get Started']");
  IWebElement webElement = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(d=>d.FindElement(byXpath));
  webElement.Click();
}
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Sorry explicit and implicit wait doesn't work in this scenario, please see the reason in the question edit section. – Pritam Karmakar Jan 06 '15 at 22:52
  • I am not very familiar with `Appium` but seems like you need to switch the focus on the DialogFragment somehow – Saifur Jan 06 '15 at 23:02