Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium C# Open New Tab CTRL+T Not working 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 its not working, I am not getting any errors nothing, the driver opens Google and thats all.... I have searched a lot and found many tutorials even videos where people are using the exact same code and it works for them, but for me it doesnt and I can't figure it out...

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

I have also tried

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

And it still does not work, but again if I change Keys.Control to Keys.Shift it writes, seems like nothing that involves Keys.Control is working!!

Edit: I have tried running the code with a IE Driver and it worked there, it opens new tab, but it does not open new tabs on Chrome?

like image 959
Darkbound Avatar asked Apr 26 '17 21:04

Darkbound


People also ask

What is Selenium C# used for?

Selenium is an open-source Web UI automation testing suite. It was developed by Jason Huggins in 2004 as an internal tool at Thought Works. It supports automation across different browsers, platforms, and programming languages which includes Java, Python, C#, etc.

Does Selenium support C language?

Conclusion: > Selenium WebDriver supports various programming languages like Java, Python, C#, Ruby, Perl, PHP, JavaScript, R, Objective-C and Haskell.

Can we use Selenium with C ++?

Webdriver++ is a C++ client library for Selenium Webdriver which you have to install and have the following feature support: Chainable commands. Value-like objects compatible with STL containers.

Which is better Selenium with Java or C#?

For Java, there is large support available online, as most of the professionals are using Selenium with Java. Rank wise Java is among the top 3 most popular languages, C# is not. On the other hand for C# if you stuck at any point then it would be quite difficult to get help from the online community.


2 Answers

Thanks for the answers! I did it with JavaScript.

((IJavaScriptExecutor)driver).ExecuteScript("window.open();");
like image 112
Darkbound Avatar answered Sep 17 '22 10:09

Darkbound


Looks like it's a "feature" of the chrome driver.

https://bugs.chromium.org/p/chromedriver/issues/detail?id=581

This is a limitation in the way we simulate keyboard input in ChromeDriver. Keys get sent directly to the render process, bypassing the browser process. So any keyboard shortcut handlers in the browser process will not be invoked by sendKeys().

like image 33
Sunshine Avatar answered Sep 20 '22 10:09

Sunshine