JPaulPunzalan JPaulPunzalan -3 years ago 155
ASP.NET (C#) Question

Open a new tab in an existing browser session using Selenium

My current code below in C# opens a window then navigates to the specified URL after a button click.

protected void onboardButton_Click(object sender, EventArgs e)

IWebDriver driver = new ChromeDriver();

driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");


But the site that I am planning to navigate to has single sign-on. How can I open a new tab in my existing browser session and navigate from there? The above code does not seem to work.

Thanks a million!

Answer Source

To handle new tab you should switch to it first. Try following:

driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");

Also you might need to switch back:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download