Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 665
User Avatar asked Feb 19 '14 01:02

User


1 Answers

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.

like image 130
luksch Avatar answered Nov 08 '22 09:11

luksch