C# chrome webdriver无法打开新选项卡

C# chrome webdriver无法打开新选项卡,c#,selenium,selenium-chromedriver,C#,Selenium,Selenium Chromedriver,我试图在Selenium.WebDriver.ChromeDriver“version=”2.21.0.0“中打开一个新选项卡,但它没有打开任何内容,但是如果我将调试跟踪步骤移回行“body.SendKeys(Keys.Control+'t')”以便第二次重新运行,它会工作吗 var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); IWebElement body = wait.Until(ExpectedCondi

我试图在Selenium.WebDriver.ChromeDriver“version=”2.21.0.0“中打开一个新选项卡,但它没有打开任何内容,但是如果我将调试跟踪步骤移回行“body.SendKeys(Keys.Control+'t')”以便第二次重新运行,它会工作吗

  var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
  IWebElement body = wait.Until(ExpectedConditions.ElementIsVisible(By.TagName("body")));                          
                            Thread.Sleep(2000);
                            body.SendKeys(Keys.Control + 't');
更新:它似乎停止了chrome,它确实正确地打开了选项卡。因此,不要使用Thread.sleep,只需尝试:

 IJavaScriptExecutor js = driver as IJavaScriptExecutor;
 js.ExecuteScript("return window.stop");
 body.SendKeys(Keys.Control + 't');

请使用以下代码解决您的问题:

Actions act = new Actions(driver);
act.sendKeys(Keys.CONTROL,"t").build().perform();

请使用以下代码解决您的问题:

Actions act = new Actions(driver);
act.sendKeys(Keys.CONTROL,"t").build().perform();

要使用Chrome打开新选项卡,请执行以下操作:

    var driver = new ChromeDriver();

    driver.Navigate().GoToUrl("http://stackoverflow.com");

    // open a new tab and set the context
    driver.ExecuteScript("window.open('_blank', 'tab2');");
    driver.SwitchTo().Window("tab2");

    driver.Navigate().GoToUrl("https://www.google.com");

要使用Chrome打开新选项卡,请执行以下操作:

    var driver = new ChromeDriver();

    driver.Navigate().GoToUrl("http://stackoverflow.com");

    // open a new tab and set the context
    driver.ExecuteScript("window.open('_blank', 'tab2');");
    driver.SwitchTo().Window("tab2");

    driver.Navigate().GoToUrl("https://www.google.com");

谢谢,我以前用过同样的方法,是的,到目前为止,这是我唯一能让功能正常工作的方法。谢谢,我以前用过同样的方法,是的,到目前为止,这是我唯一能让功能正常工作的方法。你确定这是给C的吗?你确定这是给C的吗?