Selenium,如何用插件启动Firefox?

2024-04-29 09:45:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想加载Firefox插件请求策略。我就是这样尝试的:

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()

没有错误,according to the Docs它应该可以工作,但它不能工作,它仍然在没有加载项的情况下启动。

接下来我试着这样称呼它:

self.driver = webdriver.Firefox(browser_profile=firefoxProfile)

输出:

TypeError: __init__() got an unexpected keyword argument 'browser_profile'

但这是python的一个方面,我不太了解。我有这个想法是因为source看起来是那样的。


Tags: selfbrowser插件usrdriveropenfirefoxprofile
3条回答

我所做和工作的是:

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://.....

另外,您不应该直接打开xpi文件。相反,试着给出地址:

firefoxProfile.add_extension(wd + "/requestpolicy.xpi")

我没有足够的Stackoverflowrep来对你的问题发表评论,不幸的是,我不知道你的问题的答案,但是对于什么值得你调用webdriver.Firefox()的firefox配置文件,而不是像你所做的那样。

另请参见:http://code.google.com/p/selenium/source/browse/trunk/py/selenium/webdriver/firefox/webdriver.py#33

相关问题 更多 >