我尝试在java中隐藏控制台和GhostDriver的日志......
- Windows 7.
- JDK is in 1.7.0_75 version.
- PhantomJS 1.9.7 is include with it path.
- GhostDriver 1.1.0 is include in an Eclipse Java SE Project.
- Selenium 2.43.1 is include in an Eclipse Java SE Project.
有办法吗?
我在cli_args中尝试过“--webdriver-loglevel = OFF”和“--webdriver-loglevel = NONE”,但它不起作用......
我试过java -jar myJar.jar> myFile.txt但它不起作用......
是否存在其他方式或可能是错误?
代码示例:
WebDriver driver;
DesiredCapabilities dCaps;
dCaps = new DesiredCapabilities();
dCaps.setJavascriptEnabled(true);
dCaps.setCapability("takesScreenshot", true);
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=false", "--webdriver-loglevel=OFF", "--webdriver-loglevel=NONE"});
dCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantom);
driver = new PhantomJSDriver(dCaps);
日志(带有VM参数):
mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFOS: executable: C:\Users\212428788\workspace\BigBrowser\phantomjs-1.9.7-windows\phantomjs.exe
mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFOS: port: 48921
mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFOS: arguments: [--ignore-ssl-errors=true, --ssl-protocol=tlsv1, --web-security=false, --webdriver-loglevel=OFF, --webdriver-loglevel=NONE, --webdriver=48921, --webdriver-logfile=C:\Users\212428788\workspace\BigBrowser\phantomjsdriver.log]
mai 18, 2015 2:09:48 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFOS: environment: {}
PhantomJS is launching GhostDriver...
非常感谢。
答案 0 :(得分:3)
查看以下步骤是否适合您(从this主题回答):
像这样创建一个String数组:
String[] phantomArgs = new String[] {
"--webdriver-loglevel=NONE"
};
将以下行添加到DesiredCapabilities
:
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
我对PhantomJSDriver的配置是这样的:
//set binary path of phantomJS driver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "drivers/phantomjs.exe");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX,"Y");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
capabilities.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:16.0) Gecko/20121026 Firefox/16.0");
//intialize driver and set capabilties
PhantomJSDriver driver = new PhantomJSDriver(capabilities);
右键单击您的项目,然后选择运行方式 - >运行配置 - >参数,并将VM参数-Djava.util.logging.config.file=logging.properties
添加到VM参数:
点击应用,然后运行
答案 1 :(得分:-1)
我找到了答案,只需将jar安装为Windows服务......