unable to switch to 'current active tab' in chrome using webdriver in java

577 views
Skip to first unread message

SamMat

unread,
Mar 15, 2016, 8:33:22 AM3/15/16
to Selenium Users

I am unable to switch to the 'current active tab' in Chrome using WebDriver. I have tried the following:
We can switch to tab, however we do not know which one is the current active selected tab

  1. I have tried driver.switchTo().activeElement() however it is of no help
  2. I have tried driver.switchTo().Window(""), doesn't work
  3. Tried the following snippet.
Set<String> allWindowHandles = driver.getWindowHandles();  
  for (String windowHandle : allWindowHandles) {
   if (!windowHandle.equals(<cannot get the active selected window handle>)) {
      driver.switchTo().window(windowHandle);
   }
}

However getting the current active selected tab handle is the issue.

Chris Merrill

unread,
Mar 15, 2016, 3:07:49 PM3/15/16
to Selenium Users
Use getWindowHandle() to get the current handle. You can then use that handle later to switch to it.

https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.html#getWindowHandle%28%29

But from the way you've worded the question, I'm a bit confused. You never need to switch TO the current window - by definition, you're already on it. Unless a human user has intervened and you're trying to recover?

Chris
Reply all
Reply to author
Forward
0 new messages