当运行普通的PhantomJS时,可以设置config.json来设置一些选项。使用Selenium WebDriver时如何使用JSON文件设置PhantomJS?
我有这个:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"/usr/local/bin/phantomjs");
driver = new PhantomJSDriver(caps);
答案 0 :(得分:2)
在简单的PhantomJS中,--config=config.json
命令行选项在运行时可以指定为here。通过selenium webdriver调用PhantomJS时,可以通过将此命令行选项传递给功能来指定相同的内容:
ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--config=config.json");
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability("takesScreenshot", false);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"/usr/local/bin/phantomjs");
WebDriver driver = new PhantomJSDriver(capabilities);
这改编自我的回答here。