9

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?

Community
  • 1
  • 1
Tiffany G
  • 203
  • 4
  • 9
  • Could you a elaborate more please? How you got nil? Where you found that output? – Arup Rakshit Jul 24 '13 at 20:54
  • I attempted to pass this code in a debugger mode at the command line so that I could see first hand if any errors were returned that were being ignored. It would appear that 'nil' is what the action builder returns when there is no error. So, when I attempted to use this code on Firefox, and it was successful, nil was returned. When I attempted to use this code on chrome, and it wasn't successful, nil was also returned. However, when something was syntactically wrong (say I tried to pass "i" using the key_down method), an error was shown at the command prompt. – Tiffany G Jul 24 '13 at 21:10
  • i can see `.send_keys("i")`. You did not pass *i* with `key_down`. – Arup Rakshit Jul 24 '13 at 21:27
  • Priti, I know I didn't send i with key_down. I was using that as an example to show that if you did something syntactically wrong you get an error, and if the syntax is correct, nil is returned. – Tiffany G Jul 24 '13 at 21:31
  • Google Chrome 23.0.1271.95 ChromeDriver 21.0.1180.4 – Tiffany G Jul 24 '13 at 21:45
  • @TiffanyGoffe Unfortunately, as far as I know, this is the best solution you can get out of Selenium itself. If Ruby itself (I'm a Java guy) can press virtual keys programatically, you might try that (in Java, that would be the [`Robot`](http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html) class). – Petr Janeček Jul 24 '13 at 22:03
  • An alternatively if you are working with Windows will be the win32ole. You can sent practically all key strokes and combos with that! – Xwris Stoixeia Jul 26 '13 at 13:40
  • Thanks, @XwrisStoixeia. These are actually running on Linux, but that's definitely some information I should have given in the original explanation. I'll update. – Tiffany G Jul 26 '13 at 14:40
  • UPDATE: I logged a ticket with Chrome for this a while back. They actually know about the issue and, although they don't give a workaround, they talk about it at https://code.google.com/p/chromedriver/issues/detail?id=677. – Tiffany G Feb 12 '14 at 22:39

3 Answers3

1

In Selenium I have used :

function key F12.

driver.FindElement(By.XPath("String")).SendKeys(Keys.F12);
Peter
  • 663
  • 1
  • 7
  • 15
0

I think you're just using a wrong keys combination. According to this: https://support.google.com/chrome/answer/171571?hl=en&ref_topic=25799, the shortcut to open Developer Tools is Ctrl-Shift-J on Linux and Windows and Cmd-Opt-I on Mac.

szeryf
  • 3,197
  • 3
  • 27
  • 28
0

You can use robot class of java, if you want to open dev-tools.

    try{
        Robot robot=new Robot();
        robot.keyPress(KeyEvent.VK_F12);
        robot.keyRelease(KeyEvent.VK_F12);  
    }
    catch(Exception ex){
        System.out.println(ex.getMessage());
    }
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125