5
votes

I am trying to open developer console in chrome using selenium webdriver. I am doing

from selenium import webdriver

from selenium.webdriver.common import action_chains, keys

...

browser = webdriver.Chrome(executable_path="C:\chrm\chromedriver.exe") browser.get("https://www.facebook.com/groups/GNexus5/")

...

action = action_chains.ActionChains(browser)

action.send_keys(keys.Keys.CONTROL+keys.Keys.SHIFT+'j')

action.perform()

But it is not opening up developer console. I have tried other keys (just typing some key-strokes, control-selecting some element) and they are working.

I am using ChromeDriver

5

5 Answers

2
votes

Only if you are in desperate and your OS is Windows, you can simply do this with adding AutoHotKey script to Python code. You can download AutoHK from here

Install AutoHK. Then you create new script in notepad: just put one short string

Send ^+J

and save it as script.ahk. These actions will takes 2-3 minutes. Then call it in your code

browser.get("https://www.facebook.com/groups/GNexus5/")
import os
os.system("path_to_script.ahk/script.ahk")

and this gonna work :)

4
votes

Tell selenium to include a ''auto-open-devtools-for-tabs'' when launching chrome, here is an example using nightwatch configuration:

...

chrome: {
  desiredCapabilities: {
    browserName: 'chrome',
    javascriptEnabled: true,
    acceptSslCerts: true,
    chromeOptions: {
      'args': ['incognito', 'disable-extensions', 'auto-open-devtools-for-tabs']
    }
  }
},
...
0
votes

With pyautogui you can do the keyboard press and open the console in the tab you have in foucs.

    import pyautogui
    pyautogui.keyDown('ctrl')
    pyautogui.keyDown('shift')
    pyautogui.press('j')
    pyautogui.keyUp('ctrl')
    pyautogui.keyUp('shift')
0
votes

While it's not opening the dev-tools pane itself, I would refer you to this answer which explains how to run commands specific to the dev-tools console.

If you really need to open the pane itself, there's probably an answer in the dev-tools documentation.

FYI You need Selenium version 4.0.0.b3 to do these actions. Dev-tools isn't supported in the stable release.

-3
votes

driver.find_element_by_xpath(<any element_name on the webpage>).send_keys(Keys.F12)

This opens the developer console directly!

You can also use other find_by methods.