Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open chrome developer console using Selenium in Python?

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

like image 658
travis bickle Avatar asked Jun 19 '15 06:06

travis bickle


2 Answers

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']
    }
  }
},
...
like image 149
Manel Clos Avatar answered Nov 14 '22 23:11

Manel Clos


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')
like image 25
Jortega Avatar answered Nov 14 '22 22:11

Jortega