4
  1. webElement.SendKeys(Keys.Control + "t"); This code is not working for me.
  2. String n = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.id("open-tab")).sendKeys(n); In which key.chord is not working for selenium C#.
  3. driver.SwitchTo().Window(driver.WindowHandles[0]); this one is also not working with my code. Is any alternative way available for switching tab.

1 Answer 1

9

Selenium 4 solution:

driver.SwitchTo().NewWindow(WindowType.Tab);

Note that it will open a new tab in the same window and will switch also to the newly opened tab.

to open a new window, you should use:

driver.SwitchTo().NewWindow(WindowType.Window);

Selenium 3 solution:

((IJavaScriptExecutor)driver).ExecuteScript("window.open()");
List<string> tabs = new List<string> (driver.WindowHandles);
driver.SwitchTo().Window(tabs[1]);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.