[英]Selenium, how to start Firefox with addons?
我想加载 Firefox 插件 RequestPolicy。 这就是我尝试的方式:
rp = open(wd + "/requestpolicy.xpi")
firefoxProfile = FirefoxProfile()
firefoxProfile.add_extension(rp)
self.driver = webdriver.Firefox(firefoxProfile)
self.usr = user.User(self.driver, username, password, world)
self.usr.login()
没有错误, 根据文档它应该可以工作,但它没有,它仍然在没有插件的情况下启动。
我试过的下一件事就是这样称呼它:
self.driver = webdriver.Firefox(browser_profile=firefoxProfile)
输出:
TypeError: __init__() got an unexpected keyword argument 'browser_profile'
但这是我不太了解的python的一个方面。 我有这个想法是因为源看起来是这样的。
我没有足够的 Stackoverflow代表来对您的问题发表评论,不幸的是我不知道您的问题的答案,但是对于您需要使用firefox_profile而不是browser_profile调用webdriver.Firefox()
的价值你已经完成了。
另见: http : //code.google.com/p/selenium/source/browse/trunk/py/selenium/webdriver/firefox/webdriver.py#33
我所做的和工作的是:
profile=webdriver.FirefoxProfile()
profile.add_extension("/home/.../.mozilla/firefox/zrdb9ki8.default/extensions/{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}.xpi") # for adblockplus
profile.set_preference("extensions.adblockplus.currentVersion", "2.8.2")
Fox = webdriver.Firefox(profile)
Fox.get(website_Url) #https://.....
我花了几个小时才找到解决方案。
您需要做的就是将扩展名下载为 .xip 文件。
然后将此行添加到您的代码中:
driver.install_addon('/Users/someuser/app/extension.xpi', temporary=True)
将“/Users/someuser/app/extension.xpi”替换为您的扩展 .xip 文件的路径。
此外,您不应直接打开 xpi 文件。 而是尝试只提供地址:
firefoxProfile.add_extension(wd + "/requestpolicy.xpi")
O Selenium IDE não funciona mais com o Firefox 95.0.2?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.