How do you create a browser profile for Selenium's PhantomJS/GhostDriver?

耗尽温柔 提交于 2019-12-04 02:55:48

问题


Here's how you create a Firefox profile:

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.dir", download_dir)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")

How do you do it with PhantomJS (GhostDriver)?


回答1:


The closest you can get with phantomjs is to use the driver capabilities:

DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability( "phantomjs.page.settings.userAgent", "Mozilla");
Set<String> cliArgs = new HashSet<>();
cliArgs.add("--ignore-ssl-errors=true");
cliArgs.add("--ssl-protocol=any");
cliArgs.add("--web-security=false");
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs);
driver = new PhantomJSDriver(caps);

However, you notice that there are no configuration options for automatic downloading, since phantomjs does not support this. It is anyway not a very good idea to use selenium for testing of downloads. I did answer another related question earlier in which I point to an article about this and why you should not do it.



来源:https://stackoverflow.com/questions/21868957/how-do-you-create-a-browser-profile-for-seleniums-phantomjs-ghostdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!