100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > python+selenium+firefox加载配置文件 无法自动启用插件的问题

python+selenium+firefox加载配置文件 无法自动启用插件的问题

时间:2022-12-15 12:31:15

相关推荐

python+selenium+firefox加载配置文件 无法自动启用插件的问题

path\firefox.exe -p

安装好插件,禁止插件自动更新,调整页面至想要的状态。

关闭firefox,配置文件已自动保存

python中

from selenium import webdriverfp = webdriver.FirefoxOptions()fp.binary_location = r"..\Firefox\App\Firefox\firefox.exe"fp.profile = r"..\firefox-profiles-dev"# fp.set_preference("extensions.pendingOperations", True)driver = webdriver.Firefox(options=fp)

插件虽设置已启用,但实际未启动!

关闭打开后,才实际启用

复制了一份配置文件到TEMP文件夹,文件夹自动生成,每次名称不一致

在这种状态中做的所有设置,都被保存在临时文件中,下次不会再加载。

分析:

在selenium拉起 friefox中,关闭开启插件,配置文件夹中发现有以下三个文件有变动

prefs.js中user_pref键值对可以用 webdriver.FirefoxOptions的set_preference方法设置。

selenium4 有提示 “DeprecationWarning: Setting a profile has been deprecated. Please use the set_preference and install_addons methods”,不建议使用配置文件,转而使用“set_preference”来设置firefox属性

prefs.js中的键值对可用来做设置参考

比较插件重新启用前后的prefs.js

有一处与插件(extensions)相关

"extensions.pendingOperations"之前为false,重启插件后为true

python中添加一句

fp.set_preference("extensions.pendingOperations", True)

完整:

from selenium import webdriverfp = webdriver.FirefoxOptions()fp.binary_location = r"..\Firefox\App\Firefox\firefox.exe"fp.profile = r"..\firefox-profiles-dev"fp.set_preference("extensions.pendingOperations", True)driver = webdriver.Firefox(options=fp)

自动加载插件成功

分析原理

/Extension_Manager:API_Rewrite

Some types of add-ons may require restarts for certain operations.XPIstyle extensions for example require restarts for almost all operations. The API exposes the operations that are pending in thependingOperationsproperty. Pending operations can make it hard to tell what state an actual add-on is in. To help solve this the isActive property indicates whether the add-on is currently active. This is separate to and may be different to the various userDisabled, isCompatible and other properties that indicate whether an add-on can be active or not.

估计是xpi形式的插件会被挂起。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。