使用Selenium WebDriver配置RefControl扩展
我正在使用这个插件和selenium,它启动得很好,但我该如何在selenium中调整插件的设置呢?
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox import webdriver
profile = FirefoxProfile('/path/to/profile')
driver = webdriver.WebDriver(firefox_profile = profile)
driver.get("http://localhost/referer.html")
driver.find_element_by_link_text("go there").click()
问题是这个插件在你先配置之前是没有任何作用的,但我找不到相关的文档。
1 个回答
2
一般来说,正如alecxe所建议的,"首先安装并配置扩展,然后在selenium中使用那个firefox配置文件"。这样做可能适用于任何扩展。
我还在prefs.js(或者about:conf)中查找配置,发现它把值存储在"refcontrol.actions"这个设置里。通过这种方式,你就可以在代码中改变扩展的行为。举个例子:
profile = FirefoxProfile('/path/to/profile')
profile.set_preference("refcontrol.actions", '@DEFAULT=@NORMAL example.com=@3RDPARTY:http://www.referer.com/your/referer');