gpt4 book ai didi

Java 和 GhostDriver : Hide Console and Logs

转载 作者:行者123 更新时间:2023-11-30 08:52:22 24 4
gpt4 key购买 nike

我尝试在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"
    };
  • 将以下行添加到您的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);
  • 右键单击您的项目并选择 Run As->Run Configurations->Arguments 并添加 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com