Selenium for Chrome and Firefox, coding in C#, will not handle switching over to the new tab that is opening during my automation test. I don't think it focuses on the new tab open because when I run my program completely, I receive this error: "out of range" exception and "Index was out of range. Must be non-negative and less than the size of the collection."
I've tried using:
driver.SwitchTo().Window(driver.WindowHandles).Close(); // close the first tab
System.Threading.Thread.Sleep(5000); //Wait 5 seconds just in case
driver.SwitchTo().Window(driver.WindowHandles); //Makes sure I'm on the correct tab
Once you've closed
tab, the old
tab becomes the new
tab, so you should be switching to
Selenium operates in the background so the window does not need to be in focus while it is running. This also means that Selenium will never change the focus back to the browser window. If you are watching the window while your code runs however you should be able to see the browser changing tabs.