Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending keyboard shortcuts to chrome with Selenium and Ruby

I'm attempting to launch the devtools in a chrome browser on Linux by using the keyboard shortcuts. Because I'm using Ruby and it does not have a chord method, I've tried the following:

driver.action.key_down(:shift)
             .key_down(:control)
             .send_keys("i")
             .key_up(:shift)
             .key_up(:control)
             .perform

The above code will work in Firefox (as suggested in Key press in (Ctrl+A) Selenium WebDriver), but in chrome, it returns nil but no results occur.

Any advice?

like image 498
Tiffany G Avatar asked Jul 24 '13 20:07

Tiffany G


People also ask

How do I send keyboard shortcuts in Selenium?

We can send keyboard shortcut ALT SHIFT z(hotkey) with Selenium webdriver. This can be done with the help of the Keys class. We shall use the Keys. chord method and pass Keys.

How do you automate keyboard actions in Selenium?

Selenium provides various ways to automate these Keyboard Events, a few of which are: Automate keyboard events using the sendKeys() method of WebElement class. Automate keyboard events using Robot class. And Automate keyboard events using Actions class.

Does Selenium support Ruby?

Selenium is a browser-based test framework that allows one to automate user actions and interactions with web applications. You can use Selenium WebDriver APIs to devise test code using Selenium-supported languages like Ruby, Java, JavaScript, C#, and Python.


1 Answers

In Selenium I have used :

function key F12.

driver.FindElement(By.XPath("String")).SendKeys(Keys.F12);
like image 165
Peter Avatar answered Sep 20 '22 15:09

Peter