Java和GhostDriver : Hide Console and Logs

标签 java selenium phantomjs ghostdriver

我尝试在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...

非常感谢。

最佳答案

看看以下步骤是否适合您(来自 this 线程的回答):

  • 创建一个字符串数组,如下所示:

    String[] phantomArgs = new  String[] {
            "--webdriver-loglevel=NONE"
    };
    
  • 将以下行添加到您的 DesiredCapability 中:

    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。属性到VM参数:

    enter image description here

  • 点击应用,然后点击运行

关于Java和GhostDriver : Hide Console and Logs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30192319/

相关文章:

python - Selenium + Python如何监听元素的变化

javascript - this.evaluate 使用函数参数来实现大型可重用函数

javascript - 将来自 AngularJS 应用程序的模块文件包含到 Karma 中的 RequireJS 配置文件中

javascript - CasperJS 屏幕截图未将图像渲染为 png 文件

java - 在 Cucumber Stepdefs 中抛出异常

java - 导入的 java 类中的公共(public)静态最终变量

python - 如何使用 python 和 selenium 网络抓取具有相同类名的表数据(包括合并的单元格)

python - 浏览器处理工作的 Mechanize 替代方案?

java - 如何在运行时收集所有实现接口(interface)的类?

java - 从 xy 移动到另一点,我在时间 t 在哪里?