使用firefoxprofile,selenium设置firefox,初始化firefox

1、什么是firefoxprofile

      简单的来说就是个人定制,比如你设置自己访问主页,禁用加载图片这些个性化的设置,都可以保存到一个文件夹下,就是firefoxprofile,下次使用时候,加载该firefoxprofile,就可以让自己火狐浏览器设置跟之前配置一样

2、为什么selenium要用firefoxprofile

     我们自动化测试的时候,有时不需要图片加载出来,提高浏览器加载速度,从而提高脚本的执行速度。另外在一些网络比较差的环境下,禁用css、图片等加载可以提高访问速度

方法:

      1、创建自己的firefoxprofile

关闭所有Filefox浏览窗—》运行Firefox Manager,点击windows“开始”-->“运行”,然后在输入框输入firefox.exe -ProfileManager,点击“确定”按钮-》创建一个新的Profile,只需点击“创建配置文件”按钮,在接着出现的向导窗口里输入配置文件名

现在就创建了一个独立的Firefox Profile配置文件,启动Profile配置文件的Firefox

新建一个bat文件,输入命令行

set MOZ_NO_REMOTE=1
start "" "C:Program FilesMozilla Firefox Formalfirefox.exe" -P firefoxprofile文件名

在新打开的浏览器中,你可以随意设置火狐,这些设置都保存在你的个性化firefoxprofile中

     2、现在使用selenium调用firefoxprofile

firefox_profile = webdriver.FirefoxProfile("D:Downloads")

browser = webdriver.Firefox(firefox_profile=firefox_profile)
D:Downloads路径存放着我firefoxprofile
原文地址:https://www.cnblogs.com/huangweiping/p/5398616.html