How to open a new tab using Selenium WebDriver?

后端 未结 29 2795
野的像风
野的像风 2020-11-22 04:40

How to open a new tab in the existing Firefox browser using Selenium WebDriver (a.k.a. Selenium 2)?

29条回答
  •  自闭症患者
    2020-11-22 05:40

    To open a new tab in the existing Chrome browser using Selenium WebDriver you can use this code:

    driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");        
    string newTabInstance = driver.WindowHandles[driver.WindowHandles.Count-1].ToString();
    driver.SwitchTo().Window(newTabInstance);
    driver.Navigate().GoToUrl(url);
    

提交回复
热议问题