title: Explicit Wait for automating windows application using winappdriver
body: <p>I am a newbie to Windows Application Driver and my project demands automating the desktop application, so I decided to use winappdriver as it is similar to selenium, on which I am pretty confident about using.</p>
  
  <p>speaking of the issue,
  Just wondering if there is a way to achieve explicit wait and implicit wait using winappdriver. Following is the code i used as part of my test cases, the test fails with an exception (NoSuchElementException), however, if I put a static wait in place instead of explicit wait, it works as expected.</p>
  
  <pre><code> //Driver Setup
  public class OscBase {
  
  public static WindowsDriver&lt;WebElement&gt; applicaitonSession, driver = null;
  public static WindowsDriver&lt;RemoteWebElement&gt; desktopSession = null;
  public static DesiredCapabilities capabilities, cap1, cap2;
  public static ProcessBuilder pBuilder;
  public static Process p;
  
  public void startDriver() {
      try {
  
          pBuilder = new ProcessBuilder("C:\\Program Files (x86)\\Windows Application Driver\\WinAppDriver.exe");
          pBuilder.inheritIO();
          p = pBuilder.start();
  
      }
  
      catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  public void stopDriver() {
  
      p.destroy();
  }
  
  public void createDesktopSession() throws MalformedURLException {
  
      cap1 = new DesiredCapabilities();
      cap1.setCapability("app", "Root");
      desktopSession = new WindowsDriver&lt;RemoteWebElement&gt;(new URL("http://localhost:4723"), cap1);
  }
  
  public void openApplication() throws InterruptedException, MalformedURLException {
  
      if (driver == null) {
  
          try {
  
              capabilities = new DesiredCapabilities();
              capabilities.setCapability("app",
                      "Appnamewithlocation");
              applicaitonSession = new WindowsDriver&lt;WebElement&gt;(new URL("http://localhost:4723"),
                      capabilities);
  
          } catch (Exception e) {
  
              System.out.println("Application opened!!!");
  
          } finally {
  
              createDesktopSession();
          }
  
          Thread.sleep(8000L);
  
          String handle = desktopSession.findElementByAccessibilityId("InstallerView5")
                  .getAttribute("NativeWindowHandle");
          System.out.println(handle);
          int inthandle = Integer.parseInt(handle);
          String hexHandle = Integer.toHexString(inthandle);
  
          //System.out.println(hexHandle);
  
          cap2 = new DesiredCapabilities();
          cap2.setCapability("appTopLevelWindow", hexHandle);
          driver = new WindowsDriver&lt;WebElement&gt;(new URL("http://localhost:4723"), cap2);
  
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  
      }
  
  }
  
  
  public boolean isDisplayed_SafeLoginNoBtn() {
  
      wait = new WebDriverWait(driver, 40);
      return wait.until(ExpectedConditions.visibilityOf(safeLoginNoBtn())).isDisplayed();
  
  }
  
  
  
  
  @Test
  public void osc_Get_Data() throws InterruptedException, IOException {
  
      //Thread.sleep(20000);
  
      // Boolean value=oscLogin.safeLoginNoBtn().isDisplayed();
  
      try {
          Boolean value = oscLogin.isDisplayed_SafeLoginNoBtn();
          System.out.println("IS displayed========&gt;"+value);
          if (value) {
  
              oscLogin.click_safeLogin();
          }
      } catch (Exception e) {
  
          System.out.println("Safe Login!!!!");
      }
  </code></pre>