![](/img/trans.png)
[英]How can i use Selenium WebDriver to open chrome new tab window in the background?
[英]chrome webdriver cannot open new tab
我正在尝试在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');
要使用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");
使用以下代码解决您的问题:
Actions act = new Actions(driver);
act.sendKeys(Keys.CONTROL,"t").build().perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.