如何在Python中使用Selenium打开chrome开发者控制台? [英] How to open chrome developer console using Selenium in Python?

查看:466
本文介绍了如何在Python中使用Selenium打开chrome开发者控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium Webdriver在Chrome中打开开发者控制台. 我在做

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

从硒导入网络驱动程序

from selenium import webdriver

从selenium.webdriver.com常见导入action_chains,密钥

from selenium.webdriver.common import action_chains, keys

...

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

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

...

action = action_chains.ActionChains(浏览器)

action = action_chains.ActionChains(browser)

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

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

action.perform()

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.

我正在使用ChromeDriver

I am using ChromeDriver

推荐答案

仅当您绝望而您的操作系统是Windows时,才可以通过向Python代码添加AutoHotKey脚本来简单地做到这一点.您可以从此处

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

安装AutoHK.然后在记事本中创建新脚本:只需输入一个短字符串

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

Send ^+J

,并将其另存为script.ahk.这些操作将需要2-3分钟.然后在您的代码中调用

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")

这将起作用:)

这篇关于如何在Python中使用Selenium打开chrome开发者控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆