如何为Selenium的PhantomJS/GhostDriver创建浏览器配置文件? [英] How do you create a browser profile for Selenium's PhantomJS/GhostDriver?
本文介绍了如何为Selenium的PhantomJS/GhostDriver创建浏览器配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是创建Firefox配置文件的方法:
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")
您如何使用PhantomJS(GhostDriver)?
How do you do it with PhantomJS (GhostDriver)?
推荐答案
使用phantomjs可以得到的最接近的是使用驱动程序功能:
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);
但是,您注意到没有用于自动下载的配置选项,因为phantomjs不支持此选项.无论如何,使用硒进行下载测试不是一个好主意.我之前做了回答另一个相关问题,其中我指向了
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.
这篇关于如何为Selenium的PhantomJS/GhostDriver创建浏览器配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文