webElement.SendKeys(Keys.Control + "t");
This code is not working for me.String n = Keys.chord(Keys.CONTROL, Keys.ENTER);
driver.findElement(By.id("open-tab")).sendKeys(n);
In whichkey.chord
is not working for selenium C#.driver.SwitchTo().Window(driver.WindowHandles[0]);
this one is also not working with my code. Is any alternative way available for switching tab.
How to open a new tab using Selenium WebDriver in C#?
Asked Answered
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]);
© 2022 - 2024 — McMap. All rights reserved.