1.打开cmd进放 firefox.exe所在的目录 如:D:>cd D:Mozilla Firefox
2.运行如命令:D:Mozilla Firefox>firefox.exe -ProfileManager -no-remote。出现如图
3.点击创建配置文件
4.刚创建的文件里面只有少部分内容,还要自己去配置
5.打开记事本,“开始”->“附件”->“记事本”
6.在记事本里输入:
set MOZ_NO_REMOTE=1
start "" "C:Program FilesMozilla Firefox Formalfirefox.exe" -P seo
说明: C:Program FilesMozilla Firefox Formalfirefox.exe是路径;-P后面的文字是你创建的配置文件的名称
7.把文件保存在任何一个位置,命名为“firefoxSEO.bat” ,双击“firefoxSEO.bat”,你就启动“seo”配置文件的Firefox了。
8.最后,在代码中使用如下方式启动FirefoxDriver:
- ProfilesIni allProfiles = new ProfilesIni();
- // "Selenium" is the new profile just created
- FirefoxProfile profile = allProfiles.getProfile("Selenium");
- WebDriver driver = new FirefoxDriver(profile);
- (另外我们可以看到Manager里面有个default,这个就是我们自己平时使用的Firefox Profile,也是可以在代码中使用的)