How to use WindowsDriver in Appium to wait for an element to load before clicking on it


#1

I am using Appium with Windows Driver, to test my Windows based Dot net application, using C#… I am trying to click on a link through my automation tests. When my automation test is running, then its not waiting till my element(link) in the application is loaded/visible . Because of this my test fails. Is there a WinAppDriver /Windows Driver waittillElementisvisible property (like how we have in Selenium Webdriver) so that it waits till the element is loaded ? Any help is much appreciated.


#2

Any help with this one ?


#3

You can use this:

public void WaitForElement(string IDType, string elementName, int time)
{
var wait = new DefaultWait<WindowsDriver>(driver)
{
Timeout = TimeSpan.FromSeconds(time),
PollingInterval = TimeSpan.FromSeconds(0.5)
};

        wait.IgnoreExceptionTypes(typeof(InvalidOperationException));

        wait.Until(driver =>
          {
              int elementCount = 0;
              switch (IDType)
              {
                  case "id":
                      elementCount = driver.FindElementsByAccessibilityId(elementName).Count;
                      break;
                  case "xpath":
                      elementCount = driver.FindElementsByXPath(elementName).Count;
                      break;
                  case "name":
                      elementCount = driver.FindElementsByName(elementName).Count;
                      break;
              }
              return elementCount > 0;
          });
    }