如何使用Java和Selenium为驱动程序传递无头选项? [英] How to pass a headless option for my driver using Java and Selenium?

查看:53
本文介绍了如何使用Java和Selenium为驱动程序传递无头选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Selenium和Java的帮助下设置chrome驱动程序.我希望该驱动程序可以无头执行,但我找不到出路.你能告诉我我该怎么办吗?

I am setting up a chrome driver with the help of Selenium and Java. I want this driver to be executed headless but I can't find out the way. Can you explain to me what do I need to do?

我的代码示例:

System.setProperty(CHROME_PROPERTY, LINUX_CHROMEDRIVER_PATH);
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(DEFAULT_IMPLICITY_TIME, TimeUnit.SECONDS);

推荐答案

 System.setProperty(CHROME_PROPERTY, LINUX_CHROMEDRIVER_PATH); // OS and Browser options
 ChromeOptions options = new ChromeOptions(); // create options instance
 options.addArguments("--headless"); // add an option
 driver = new ChromeDriver(options); // create a driver with the specific options instance

您只需要创建一个ChromeOptions对象,即可在其中保存您自己的驱动程序的选项.要添加自己的选项,只需使用以下命令:options.addArguments();并在括号中以字符串模式插入您的选项.

You just need to create a ChromeOptions object in which you need to save the options for your own driver. To add your own options just use this: options.addArguments(); and in the parenthesis insert your option in string mode.

有关更多详细信息和文档,请参见以下位置: http://chromedriver.chromium.org/capabilities

For more details and documentation please also check here: http://chromedriver.chromium.org/capabilities

我认为这将起作用.

这篇关于如何使用Java和Selenium为驱动程序传递无头选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆