如何导入和导出 webdriver FireFox 配置文件?
我想做的是:
from selenium import webdriver
#here I want to import the FF profile from a path
if profile:
driver = webdriver.Firefox(profile)
else:
#this is the way I get the WebDriver currently
driver = webdriver.Firefox()
#doing stuff with driver
#Here I want to save the driver's profile
#so I could import it the next time
最佳答案
您必须决定一个位置来存储缓存的配置文件,然后使用 os
库中的函数来检查该位置是否有文件,并加载它。要首先缓存配置文件,您应该能够从 webdriver.firefox_profile.path
获取配置文件的路径,然后将内容复制到缓存位置。
综上所述,我真的不建议这样做。通过缓存在测试运行时创建的配置文件,您可以让您的测试根据以前的行为发生变化,这意味着它不再是孤立的并且可以可靠地重复。我建议您从测试中单独创建一个配置文件,然后始终将其用作基本配置文件。这使您的测试可预测地重复。 Selenium 甚至设置为与此模式配合使用,因为它实际上并不使用您提供的配置文件,而是复制它并使用副本启动浏览器。
关于python - 如何在 python 中为 selenium webdriver 导入和导出 FireFox 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787777/