【问题标题】:Unable to run Chrome selenium " unknown error: cannot process extension #1"无法运行 Chrome 硒“未知错误:无法处理扩展程序 #1”
【发布时间】:2016-04-01 12:07:18
【问题描述】:

我正在尝试运行 chrome selenium 驱动程序并添加扩展:

manifest_json = """..... """
background_js = """...."""
ext_file = 'my_extention.zip'
with zipfile.ZipFile(ext_file, 'w') as zp:
    zp.writestr("manifest.json", manifest_json)
    zp.writestr("background.js", background_js)

co = webdriver.ChromeOptions()
co.add_extension(ext_file)
d = webdriver.Chrome(chrome_options=co)

这会引发错误:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot process extension #1
from unknown error: invalid public key length
  (Driver info: chromedriver=2.9.248304,platform=Linux 3.19.0-39-generic x86_64)

【问题讨论】:

    标签: python google-chrome selenium


    【解决方案1】:

    当我尝试对 .crx 进行 base64 编码以使扩展在 selenium 上运行时,我偶然发现了这个问题(这是在量角器测试的上下文中)。

    我怀疑这是因为扩展程序没有使用与尝试运行它的浏览器相同的浏览器。

    无论如何我最终都放弃了,只是我只是在 chromium 中添加了一个选项来加载未执行的扩展:

    --load-extension=path_to_the_extension_folder

    希望对你有帮助。

    【讨论】:

    • 当我将我的 *.zip chrome 扩展从一台机器移动到另一台机器时发生了这个错误。我最终得到了你的解决方案; --load-extension,反正要好很多。
    • 你能告诉我你在哪里添加了这个选项吗?
    • 如果您使用命令行运行 chrome/chromium,它将是 ./chrome.exe --load-extension=path_to_the_extension_folder
    猜你喜欢
    • 2018-03-07
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    相关资源
    最近更新 更多