title: How do I wait for an element using the WinAppDriver in UWP?
body: <p>I'm currently migrating my Coded UI Tests for a UWP app to Appium using the <a href="https://github.com/microsoft/WinAppDriver" rel="nofollow noreferrer">WinAppDriver</a> and I have come across the issue, that I can't wait for an element to show up. There is no way to wait for a element to be "ready" as the Coded UI Test from Microsoft did.</p>
  
  <p>In the <code>ClassInitialize</code> method everything works fine (data is entered on the login view) and the login button is clicked. After the click event is triggered the app shows a progress bar until the user is logged in. My problem is that I cannot wait for the components after the login process.</p>
  
  <p>I have found some code snippets, however, they don't seem to work for me. Here is the extension method I'm currently using:</p>
  
  <pre><code>public static IWebElement WaitForElement(this IWebDriver driver, By by, int timeoutInSeconds)
  {
     if (timeoutInSeconds &gt; 0){
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(timeoutInSeconds);
        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
        return wait.Until(ExpectedConditions.ElementIsVisible(by));
     }
     return driver.FindElement(by);
  }
  </code></pre>
  
  <p>I have also read that the implicit timeout for the Windows driver has to be set:</p>
  
  <pre><code>session = new WindowsDriver&lt;WindowsElement&gt;(new Uri(WindowsApplicationDriverUrl), appCapabilities);
  session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
  </code></pre>
  
  <p>and overridden in the <code>WaitForElement</code> method, which also didn't work for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/56117645/waiting-for-element-before-clicking-with-winappdriver">Waiting for element before clicking with WinAppDriver</a></p>
  
  <pre><code>[TestMethod]
  public void UploadDocuments()
  {
     var UploadButton = session.WaitForElement(By.XPath("//Button[@AutomationId='AddDocument']"), 60);
     UploadButton.Click();
  
     session.FindElementByXPath("//ToolbarWindow32[@AutomationId='1001']").SendKeys(Keys.Control + "a");
     session.FindElementByXPath("//ToolbarWindow32[@AutomationId='1001']").SendKeys(testFilesFolder);
  
     //session.FindElementByName("Open").Click();
  }
  </code></pre>
  
  <p>The test usually crashes in the first line after it's finished with the <code>ClassInitialize</code>. So I would like to wait for the 'AddDocument' button to pop up before the test carries on.</p>
  
  <p>If anyone has a solution I'd appreciate the help.
  Thanks!</p>