I know this is a contradictory topic. "Officially" the driver does not support tabs, however many places state that newly opened tabs will be available via window handles, and we can use the handles to switch between tabs. (code samples are C# but I hope there is nothing special to C# in the question)
driver.SwitchTo.Window(myHandle);
I am trying to open a link in a new tab. I have success, the browser shows the new tab, however the driver's windowhandles does not contain the newly opened tab, only the one original window handle. This seems to be logical, the tab is not a window, however again, in many places it is described that it should work, and driver treats tabs as windows. What am I missing?
Open in new tab:
// Performing Ctrl + Click on my link:
new Actions(driver)
.KeyDown(Keys.Control)
.Click(myLink)
.KeyUp(Keys.Control).Perform();
// driver.WindowHandles did **not** change, still contains one handle
// The newly opened tab can not be reached, because we can not even switch
// the driver to it.
Open in new window:
// Performing context menu and "Open new Window" on my link
new Actions(driver)
.ContextClick(myLink)
.SendKeys("w")
.Perform();
// driver.WindowHandles **changed**, contains 2 handles
// Switch to the newly opened window works:
driver.SwitchTo().Window(driver.WindowHandles.Last());
Misc information:
- Using Firefox v43.0.4
- Using Official Selenium C# bindings v2.48.2 (nuget)
- OS Windows 7 64 bit
- One of the zillon places where tabs described as working: here (see all answer and comments too)