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

user8741825 :

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);
dpapadopoulos :
 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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=91325&siteId=1