Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String findNewerWindowHandle(WebDriver driver, Set<String> baselineHandles, int timeout)
- {
- String foundHandle = "";
- long t = System.currentTimeMillis();
- long endTime = t + timeout * 1000;
- while ( foundHandle.isEmpty() && System.currentTimeMillis() < endTime )
- {
- Set<String> currentHandles = driver.getWindowHandles();
- if (currentHandles.size() != baselineHandles.size() )
- {
- for ( String currentHandle : currentHandles )
- {
- if ( !baselineHandles.contains( currentHandle ) )
- {
- foundHandle = currentHandle;
- break;
- }
- }
- }
- if ( foundHandle.isEmpty() )
- {
- try {
- Thread.sleep(250);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- // Note: could optionally check for handle found here and throw
- // an exception if no window was found.
- return foundHandle;
- }
Add Comment
Please, Sign In to add comment