2

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.

Thanks

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

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();
click(YourPageElement);
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, privacy policy and cookie policy

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