Selenium ChromeDriver switch tabs

前端 未结 5 743
走了就别回头了
走了就别回头了 2021-02-07 11:10

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

5条回答
  •  再見小時候
    2021-02-07 11:21

    After a long fight with this I was able to get this working with chrome driver. The alert message is not visible but brings tab to front and accept closes it immediately.

    //Rotate Tabs
    seleniumDriver.SwitchTo().Window(seleniumDriver.WindowHandles[currentUrlIndex]);
    IJavaScriptExecutor jscript = seleniumDriver as IJavaScriptExecutor;
    jscript.ExecuteScript("alert('Focus')");
    seleniumDriver.SwitchTo().Alert().Accept();
    

提交回复
热议问题