webdriver启动chrome、firefox前,读取个人配置文件

转自:http://www.vingo.cn/vingo/?p=1172

webdriver在打开chrome、firefox浏览器时,默认是创建新用户,每次打开都是一个全新的浏览器。对于浏览器需要使用npapi插件,会有困扰。通过加载个人配置文件的方式,在第一次打开浏览器时,手动设置npapi插件是否加载,后续运行直接使用之前的配置信息,不会反复提示。

chrome:
ChromeOptions options = new ChromeOptions();
options.addArguments(“–user-data-dir=C:/Users/xxx/AppData/Local/Google/Chrome/User Data/Default”);
WebDriver driver = new ChromeDriver(options);

firefox:
FirefoxProfile fp = new FirefoxProfile();
ProfilesIni allProfiles = new ProfilesIni();
fp = allProfiles.getProfile(“default”);
WebDriver driver = new FirefoxDriver(fp);

猜你喜欢

转载自xinklabi.iteye.com/blog/2215937