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");
driver.Navigate().GoToUrl("http://www.google.com")
}
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!
Change this to:
I do not know why. May be the IWebDriver miss the method.
To handle new tab you should switch to it first. Try following:
Also you might need to switch back:
This may not works:
Alternative: Find clickable element with target blank (search for "blank" in page's surce code). This will open new tab.
Than switch between tabs (thanks @Andersson) with:
Sending
Keys.Control + "t"
didn't work for me. I had to do it with javascript and then switch to it.