Selenium ChromeDriver switch tabs

前端 未结 5 744
走了就别回头了
走了就别回头了 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:39

    In C# I used the below lines to switch between the two tab.

    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;   
    js.ExecuteScript("window.open();");   
    IList tabs = new List(driver.WindowHandles);    
    driver.SwitchTo().Window(tabs[1]);
    driver.Navigate().GoToUrl("http://www.google.com");
    

提交回复
热议问题