问题
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