java 如何使用 Geckodriver 在 Selenium 中禁用 Firefox 登录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41387794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I disable Firefox logging in Selenium using Geckodriver?
提问by maxbfuer
I am using:
我在用:
- firefox version 50.1.0
- geckodriver version 0.11.1
- selenium-java 3.0.1
- 火狐版本 50.1.0
- 壁虎驱动程序版本 0.11.1
- 硒-java 3.0.1
I have tried
我努力了
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.log.browser.ignore", true);
profile.setPreference("webdriver.log.driver.ignore", true);
profile.setPreference("webdriver.log.profiler.ignore", true);
FirefoxDriver driver = new FirefoxDriver();
and
和
LoggingPreferences preferences = new LoggingPreferences();
preferences.enable(LogType.BROWSER, Level.OFF);
preferences.enable(LogType.CLIENT, Level.OFF);
preferences.enable(LogType.DRIVER, Level.OFF);
preferences.enable(LogType.PERFORMANCE, Level.OFF);
preferences.enable(LogType.SERVER, Level.OFF);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.LOGGING_PREFS, preferences);
FirefoxDriver driver = new FirefoxDriver(capabilities);
neither of these methods does anything to stop logging. Here is console output if that helps somehow:
这些方法都没有停止记录。这是控制台输出,如果有帮助的话:
- first method: http://pastebin.com/23nate2G
- second method: http://pastebin.com/NwmWEeXT
- 第一种方法:http: //pastebin.com/23nate2G
- 第二种方法:http: //pastebin.com/NwmWEeXT
For those wondering, i have log4j 1.2.17 in my pom.xml
but have no log4j.properties
or log4j.xml
and I do not use it at all.
对于那些想知道的人,我有 log4j 1.2.17,pom.xml
但没有log4j.properties
或log4j.xml
我根本不使用它。
To clarify: when I say logging I mean the console output in IntelliJ IDEA. I am using Java.
澄清一下:当我说日志记录时,我指的是 IntelliJ IDEA 中的控制台输出。我正在使用 Java。
回答by Michael Medina
To not see the logs in the console you can use the following:
要在控制台中看不到日志,您可以使用以下命令:
System.setProperty("webdriver.gecko.driver","src/main/resources/drivers/geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
return new FirefoxDriver();
回答by voji
You can define the desired logging level over command line in geckodriver.exe.
您可以在 geckodriver.exe 中通过命令行定义所需的日志记录级别。
geckodriver.exe -help
USAGE:
geckodriver.exe [FLAGS] [OPTIONS]
...
OPTIONS:
--log <LEVEL>
Set Gecko log level [values: fatal, error, warn, info, config,
debug, trace]
If you use geckodriver from selenium, you have two option:
如果您使用 selenium 的 geckodriver,您有两个选择:
- Start geckodriver.exe separately with custom arguments, and use it from selenium over RemoteWebDriver
- Create a custom wrapper, to add extra parameters to geckodriver.exe
- 使用自定义参数单独启动 geckodriver.exe,并通过 RemoteWebDriver 从 selenium 使用它
- 创建自定义包装器,向 geckodriver.exe 添加额外参数
Example geckodriver wrapper bat file (for windows):
示例 geckodriver 包装器 bat 文件(适用于 Windows):
@ECHO OFF
ECHO Starting geckodriver: %0 %*
.\GeckoDriver\geckodriver.exe --log fatal %* > NUL 2>&1
In java you can define the geckodriver executable path, over webdriver.gecko.driversystem property:
在 java 中,您可以通过webdriver.gecko.driver系统属性定义 geckodriver 可执行路径:
System.setProperty("webdriver.gecko.driver", "c:/selenium/geckodriver/gdrvwrapper.bat");
回答by Akash
Just do this
就这样做
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
driver = new FirefoxDriver();
回答by Shantonu
For selenium 3.14.0 , this is working
对于 selenium 3.14.0 ,这是有效的
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
回答by Purusothaman S
import org.openqa.selenium.firefox.FirefoxDriver
System.setProperty(
"webdriver.gecko.driver",
"C:\Users\geckodriver-v0.22.0-win64\geckodriver.exe"
)
System.setProperty(
FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,
"true"
)
System.setProperty(
FirefoxDriver.SystemProperty.BROWSER_LOGFILE,
"d:\eclipse\scala_log.txt"
)
回答by mancocapac
This is the linux version for @voji answer above. Note as I said above in the comment. I don't believe the --log fatal does anything, at least not on linux. However the redirect to NULL works well enough for me
这是上面@voji 回答的 linux 版本。请注意我上面在评论中所说的。我不相信 --log fatal 会做任何事情,至少在 linux 上不会。但是重定向到 NULL 对我来说效果很好
"webdriver.gecko.driver": "/path-to-driver/geckodriver.sh
filename: geckodriver.sh (executable)
文件名:geckodriver.sh(可执行文件)
#! /bin/bash
echo " ARGS: " $@
geckodriver --log fatal "$@" > /dev/null 2>&1
回答by Arun VC
GeckoDriverService gecko = new GeckoDriverService(new File("c:/selenium/geckodriver.exe"), 4444, ImmutableList.of("--log=fatal"), ImmutableMap.of());
gecko.sendOutputTo(new FileOutputStream("gecko_log.txt"));
gecko.start();
FirefoxOptions opts = new FirefoxOptions().setLogLevel(Level.OFF);
DesiredCapabilities capabilities = opts.addTo(DesiredCapabilities.firefox());
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(gecko, capabilities);