Selenium ChromeDriver C # - How to send browser shortcut

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(/* my path */, options);

Any ideas?

+4
3

, Chromium . chromedriver, - JavaScript :

IJavaScriptExecutor js = myDriver as IJavaScriptExecutor;
js.ExecuteScript("window.open()"); // Open new browser tab like `CTRL + t` do
+1

, Ctrl + T, selenium.

+1

. , Chrome, Firefox IE.

public void SelectAll()
{
    (new Actions(yourDriverInstance)).SendKeys(Keys.Control).SendKeys("a").Perform();            
}

- ???

0

Source: https://habr.com/ru/post/1667985/


All Articles