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)?
luksch
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