When I click on a link in my test, it opens a new tab. I want ChromeDriver to then focus on that tab. I have tried the following code to get ChromeDriver to change tabas using
This is what worked for me:
var popup = driver.WindowHandles[1]; // handler for the new tab
Assert.IsTrue(!string.IsNullOrEmpty(popup)); // tab was opened
Assert.AreEqual(driver.SwitchTo().Window(popup).Url, "http://blah"); // url is OK
driver.SwitchTo().Window(driver.WindowHandles[1]).Close(); // close the tab
driver.SwitchTo().Window(driver.WindowHandles[0]); // get back to the main window