Selenium节点启动时将命令行参数发送到Chrome [英] Sending Command Line Parameters to Chrome When Selenium Node Starts
问题描述
我正在Windows计算机上运行带有两个节点的Selenium Hub,这些节点通过批处理脚本启动.
I'm running a Selenium Hub with 2 nodes on Windows machines which are started through batch scripts.
在这些节点上启动Chrome浏览器时
When starting the Chrome browser on these nodes with
java -jar selenium-server-standalone-2.40.0.jar -role -node -hub http...
我想有机会在启动Chrome实例时向其提供命令行参数.具体来说,我想利用
I'd like to have the opportunity to provide command line parameter to the Chrome instance when it is started. Specifically I want to make use of the
--user-agent=[user agent]
用于设置Chrome发送到网络服务器的http用户代理的参数.
parameter to set the http user agent that Chrome sends to the web server.
你们中的任何人对如何解决这个问题有想法吗?
Does anyone of you have an idea about how to go about this?
如果尝试过类似的东西
-Dwebdriver.chrome.driver=[path to chromedriver] --user-agent=[user agent]
但是当我这样做时,系统无法找到chromedriver可执行文件.
but when I do that the chromedriver executable cannout be found by the system.
很酷,会有类似的东西
-Dwebdriver.chrome.browser="user-agent=[user agent]"
但是我没有发现任何帮助.
but I did not find anything helpful.
如果有人可以在这里帮助我,那将非常好...
It would be very nice if somebody could help me out here ...
推荐答案
希望这正是您想要的.
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-agent=Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3");
您需要将此选项传递给chrome功能.
You need to pass this options to your chrome capability.
下面提供了所有chrome命令行开关的列表.
List of all command line switches of chrome are provided below.
http://peter.sh/experiments/chromium-command-line-switches/
这篇关于Selenium节点启动时将命令行参数发送到Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!