我尝试使用指定的配置文件启动firefox:
firefox_profile = webdriver.FirefoxProfile('/Users/p2mbot/projects/test/firefox_profile')
driver = webdriver.Firefox(firefox_profile=firefox_profile)
driver.get('http://google.com')
time.sleep(60)
driver.quit()
/Users/p2mbot/projects/test/firefox_profile
——这个目录是正确的firefox profile dir,我用firefox-bin --ProfileManager
创建它
但是当我检查的时候关于:缓存页在firefox via selenium中,它有不同的缓存路径:
^{pr2}$如果通过firefox bin--ProfileManager运行firefox并选择配置文件,它将显示在关于:缓存页正确路径/Users/p2mbot/projects/test/firefox_profile
为什么webdriver忽略firefox的配置文件路径?有了chrome就没有这个问题了。在
我花了大约2个小时(是的,我太慢了)猜测为什么没有工作。我找到了个人资料为什么不存回来。在
当然,传递给
FirefoxProfile("myprofile/full/path")
的配置文件是在运行时使用的,但是它没有被保存回,因为(也许不明显)selenium是用于测试的,测试应该在没有缓存的情况下运行,完全没有配置文件,尽可能干净。在配置文件功能的构建(可能)是为了在运行测试之前安装某些扩展和设置,但不是为了保存它们。在
诀窍是打印出
print driver.firefox_profile.path
。它确实与通常的不同,它的名称是tmp/tmpOEs2RR/webdriver py profilecopy,而不仅仅是tmp/tmpOEs2RR/,所以阅读时应该会猜到某个配置文件正在被使用。在现在,唯一剩下的就是把它拿回来:)
运行此脚本,安装某些内容,编辑某些内容,然后再次运行;):
您可以遵循该模式,或者根据需要简单地编辑FirefoxProfilea。在
相关问题 更多 >
编程相关推荐