将选项传递给chrome驱动程序selenium [英] Passing options to chrome driver selenium
问题描述
我正在尝试禁用Chrome控制台的输出。如果我通过--start-maximized选项,它可以正常工作。我可能有错误的命令?
I am trying to disable the output to the console for chrome. If I pass the --start-maximized option it works fine. I may have the wrong command?
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--silent"));
chrome = new ChromeDriver(_chromeservice,capabilities);
我也试过
ChromeOptions options = new ChromeOptions();
options.addArguments("silent");
chrome = new ChromeDriver(options);
输出
已启动ChromeDriver端口= 26703版本= 23.0.1240.0
log = / Brett / workspace / TestNG / chromedriver.log
[1214/161331:错误:ipc_sync_channel.cc(378)]取消挂起发送
[1214/161331:错误:ipc_sync_channel.cc(378)]取消待定发送
[1214/161331:错误:ipc_sync_channel.cc(378)]取消挂起
sendingBlockquote
Started ChromeDriver port=26703 version=23.0.1240.0 log=/Brett/workspace/TestNG/chromedriver.log [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sendsBlockquote
推荐答案
这是 Chromedriver ticket (关于 silent
选项),我查看了 ChromeDriverService .java
,并找到对webdriver.chrome.logfile
的引用。
Hinted by this Chromedriver ticket (about the silent
option), I looked in the source of ChromeDriverService.java
, and found a reference to "webdriver.chrome.logfile"
.
添加 -Dwebdriver.chrome后。 logfile =/ dev / null
到我的 java
命令,日志再次变得可读:无用的ChromeDriver日志消失了,而 System.out.println
调用和异常仍显示在控制台中。
After adding -Dwebdriver.chrome.logfile="/dev/null"
to my java
command, the logs became readable again: The usless ChromeDriver logs were gone, while theSystem.out.println
calls and exceptions are still shown in the console.
我启动 java
,包含以下参数(Linux / Mac):
I start java
with the following parameters (Linux / Mac):
DIR=path/to/dir/containing/selenium/and/stuff
cd "$DIR" && java -cp "$DIR\
:$DIR/output\
:$DIR/bin/selenium-server-standalone-2.33.0.jar" \
-Dwebdriver.chrome.driver="$DIR/bin/chromedriver" \
-Dwebdriver.chrome.args="--disable-logging" \
-Dwebdriver.chrome.logfile="/dev/null" \
AllTests
如果你在Windows上:
If you're on Windows:
set DIR=path\to\dir\containing\selenium\and\stuff
cd "%DIR%" && java -cp "%DIR%;%DIR%\output;%DIR%\bin\selenium-server-standalone-2.33.0.jar" ^
-Dwebdriver.chrome.driver="%DIR%\bin\chromedriver.exe" ^
-Dwebdriver.chrome.args="--disable-logging" ^
-Dwebdriver.chrome.logfile=NUL ^
AllTests
我的类路径的组成说明( -cp
):我的测试位于$ DIR / output的目录中。 Selenium jar文件放在$ DIR / bin / selenium-server-standalone-2.33.0.jar中。 AllTests是我的类的名称,包含 public static void main(String [] args)
- 这将启动我的测试。
Explanation for the composition of my classpath (-cp
): My tests are located in a directory at "$DIR/output". The Selenium jar file is placed in "$DIR/bin/selenium-server-standalone-2.33.0.jar". "AllTests" is the name of my class containing public static void main(String[] args)
- this launches my tests.
其他参数不言自明,可根据您的需要进行调整。为方便起见(在shell / batch脚本中使用),我在变量 DIR
中声明了公共目录。
The other parameters are self-explanatory, adjust it to your needs. For convenience (used in a shell/batch script), I've declared the common directory in a variable DIR
.
这篇关于将选项传递给chrome驱动程序selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!