Selenium C # Open a new tab CTRL + T Does not work with CHROME

static void Main()
{
    IWebDriver driver = new ChromeDriver();
    driver.Navigate().GoToUrl("http://google.com");
    IWebElement body = driver.FindElement(By.TagName("body"));

    body.SendKeys(Keys.Control + "t");

}

This is the code that I am trying to use to open a new tab, and it doesn’t work, I don’t get anything, the driver opens Google, and all this .... I searched a lot and found a lot of tutorials, even videos where people use the same the code, and it works for them, but for me it is not, and I cannot figure it out ...

I tried to send Keys.Shift + "t" to the search field and it works, it writes capital T to the field

I also tried

Actions act = new Actions(driver);
act.KeyDown(Keys.Control).SendKeys("t").Perform();

And it still doesn't work, but then again, if I change Keys.Control to Keys.Shift, he writes, it seems that nothing related to Keys.Control works !!

Edit: I tried to run the code using the IE driver, and it worked there, it opens a new tab, but it does not open new tabs in Chrome?

+6
4

! JavaScript.

((IJavaScriptExecutor)driver).ExecuteScript("window.open();");
+5
+1

driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
driver.SwitchTo().Window(driver.WindowHandles.Last());
driver.Navigate().GoToUrl("http://www.google.com")
0
source

If your on mac, use Keys.Command instead of Keys.Control:

body.SendKeys(Keys.Command + "t");
0
source

Source: https://habr.com/ru/post/1016803/


All Articles