SHARE
TWEET

Untitled

a guest Dec 13th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static String findNewerWindowHandle(WebDriver driver, Set<String> baselineHandles, int timeout)
  2.     {
  3.         String foundHandle = "";
  4.         long t = System.currentTimeMillis();
  5.         long endTime = t + timeout * 1000;
  6.         while ( foundHandle.isEmpty() && System.currentTimeMillis() < endTime )
  7.         {
  8.             Set<String> currentHandles = driver.getWindowHandles();
  9.             if (currentHandles.size() != baselineHandles.size() )
  10.             {
  11.                 for ( String currentHandle : currentHandles )
  12.                 {
  13.                     if ( !baselineHandles.contains( currentHandle ) )
  14.                     {
  15.                         foundHandle = currentHandle;
  16.                         break;
  17.                     }
  18.                 }
  19.             }
  20.             if ( foundHandle.isEmpty() )
  21.             {
  22.                 try {
  23.                     Thread.sleep(250);
  24.                 } catch (InterruptedException e) {
  25.                     e.printStackTrace();
  26.                 }
  27.             }
  28.         }
  29.         // Note: could optionally check for handle found here and throw
  30.         // an exception if no window was found.
  31.         return foundHandle;
  32.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top