How to pass a headless option for my driver using Java and Selenium?

守給你的承諾、 提交于 2021-01-27 08:02:58

问题


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?

My code sample:

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

回答1:


 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

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.

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

I think this is going to work.



来源:https://stackoverflow.com/questions/54340554/how-to-pass-a-headless-option-for-my-driver-using-java-and-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!