I can switch between two tabs/windows but my requirement is to know or get active window between them.

In my project, on a click of a webElement of a page a random pop(tab/window) gets opened and I would like to know whether that(new) window has focus or my original page.

I tried to use JNA Api to get the active window and its title but my web page is remotely located.

I would like know the active window title of a browser or system which is remotely located(need this for all platforms and browsers)

Perfect solution is greatly appreciated.


  • Could you provide the code you used for that?
    – bish
    Commented Nov 1, 2015 at 11:47
  • you can find out which is active window by URL also driver.getCurrentUrl(); Commented Nov 2, 2015 at 5:08

1 Answer 1


If you perform a simple getCurrentUrl() before you click, then after that event do another getCurrentUrl(), if the values match, then your original window has focus.

pseudo code (assuming you want the focus Not to be the popup);

string pageBeforeClick = driver.getCurrentUrl();
string pageAfterClick = driver.getCurrentUrl();
assertEquals(pageBeforeClick, pageAfterClick, "Your active window is the popup");

Obviously you can wrap the last line in an if-else statement if that's what you require.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.