5 python selenium google-chrome
我正在尝试运行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)
Run Code Online (Sandbox Code Playgroud)
这引发了一个错误:
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)
Run Code Online (Sandbox Code Playgroud)
当我尝试对 .crx 进行 Base64 编码以使扩展在 selenium 上运行时(这是在量角器测试的上下文中),我偶然发现了这个问题。
我怀疑这是因为扩展程序没有使用与尝试运行它的浏览器相同的浏览器。
无论如何,我最终放弃了,只是我只是向 chromium 添加了一个选项来加载未启用的扩展:
--load-extension=path_to_the_extension_folder
我希望它有帮助。