【问题标题】:Why does Firefox not open its console using python selenium?为什么 Firefox 不使用 python selenium 打开它的控制台?
【发布时间】:2019-11-21 04:04:07
【问题描述】:

我尝试了几种通过 selenium(使用 python)在 Firefox 中打开控制台的方法,但这些方法都不起作用,尽管除了最后一种之外,我没有得到任何故障排除。

Selenium 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







【问题讨论】:

  • @DebanjnB options.add_argument("--auto-open-devtools-for-tabs") 在 OP 情况下不起作用,因为他正试图在 Firefox 中打开开发工具。所以 OP 必须使用devtools 选项,如下面我的回答所示。

标签: selenium firefox


【解决方案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 页面中获得完整的选项列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 2017-05-24
    相关资源
    最近更新 更多