1

I am using selenium in python and I am trying to open developer tools by using the following code:

from selenium import webdriver   
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()  
browser.get('http://nostarch.com')

elem = browser.find_element_by_tag_name('body')  
elem.send_keys(Keys.SHIFT, Keys.CONTROL, 'c')

But no matter how much times I try, it doesn't seem to work.
Any help would be appreciated

Andersson
  • 51,635
  • 17
  • 77
  • 129
Vagif
  • 224
  • 1
  • 3
  • 17

2 Answers2

1

If you want to open dev console try:

elem = browser.find_element_by_tag_name('body')
elem.click()
browser.switch_to.active_element().send_keys(Keys.F12)
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Thanks for your reply but unfortunately this didn't work. All the other commands like CTRL A work fine but it doesn't seem to open dev tools – Vagif Dec 21 '16 at 19:19
  • I get this error when i type browser.switch_to.active_element() i get this error: http://pastebin.com/51URKa0i – Vagif Dec 21 '16 at 20:35
  • Could you tell me what is the reason you need to open dev tools while `selenium` session? – Andersson Dec 21 '16 at 21:14
  • Hi sorry for the late reply i want to open dev tools to make a program where you can select any element on a webpage – Vagif Dec 22 '16 at 17:58
  • @Vagif.A, I'm quite sure that this is not actually what you need :) You won't be able to handle dev tools with `selenium`... But you still could try to handle web-page with `driver.page_source` + `BeautifulSoup` – Andersson Dec 22 '16 at 23:04
  • @Andersson - does the reason make a difference to the recommended solution ? – JB-007 Dec 15 '21 at 13:17
1

Check this question here it is very similiar. So, install AutoHK and open notepad and type: Send ^+J and save as script.ahk. Then, load into your file like this:

browser.get("https://www.facebook.com/groups/GNexus5/")
import os
os.system("path_to_script.ahk/script.ahk")
Bill
  • 515
  • 1
  • 4
  • 15