我尝试了几种通过selenium(使用python)在Firefox中打开控制台的方法,但是这些都没有用,尽管除了最后一种之外,我都没有进行任何故障排除。
硒3.141.0,Firefox 68.0,geckodriver-v0.24.0-win64
import selenium
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(capabilities = caps, executable_path="C:\\Users\\user_name\\API_Fire\\geckodriver.exe")
action = ActionChains(driver)
# First version I tried:
action.send_keys(Keys.CONTROL + Keys.SHIFT + 'k').perform()
# Second version I tried:
action.key_down(Keys.F12).key_up(Keys.F12).perform()
# Third version I tried:
action.key_down(Keys.CONTROL + Keys.SHIFT).send_keys('k').key_up(Keys.CONTROL + Keys.SHIFT).perform()
# Troubleshoot for third version:
InvalidArgumentException: Message: data did not match any variant of untagged enum KeyActionItem at line 1 column 1159
答案 0 :(得分:1)
如下所示添加devtools
选项。
需要在导入以下:
from selenium.webdriver.firefox.options import Options
脚本
FF_options = Options()
FF_options.add_argument("-devtools")
driver = webdriver.Firefox(firefox_options=FF_options)
您可以在firefox command line options页上获得选项的完整列表。