How to send Chrome shortcut using Selenium? I mean shortcuts like Ctrl+ S, Ctrl+ Tor Ctrl+ P, which has nothing to do with WebElements. I read a lot of similar questions, but none of the proposed solutions work for me.
Say I want to open a new tab ( Ctrl+ T) in a browser, I tried all the following code without success:
The "standard" way:
IWebElement body = myDriver.FindElement(By.TagName("body"));
body.SendKeys(Keys.Control + "t");
Way of action:
Actions action = new Actions(myDriver);
action.SendKeys(Keys.Control + "t").Build().Perform();
ChromeDriver 1 method:
if(myDriver is ChromeDriver)
{
ChromeDriver chromeDriver = myDriver as ChromeDriver;
chromeDriver.Keyboard.SendKeys(Keys.Control + "t");
}
ChromeDriver 2 method:
ChromeDriver chromeDriver = myDriver as ChromeDriver;
chromeDriver.Keyboard.PressKey(Keys.Control);
chromeDriver.Keyboard.PressKey("t");
chromeDriver.Keyboard.ReleaseKey(Keys.Control);
chromeDriver.Keyboard.ReleaseKey("t");
Please note that the first method I talked about worked for me with a different WebDriver than with Chrome. I use:
- Selenium 3.0.1
- ChromeDriver 2.27.440174
And my driver initialization is really basic:
ChromeOptions options = new ChromeOptions();
this.myDriver = new ChromeDriver(, options);
Any ideas?