Headless automation with Nodejs Selenium Webdriver

I am working with an automation tool which has to be deployed inside an ubuntu server, my wonder is if is possible to use chrome in a silent way with Selenium Webdriver.

I’ve tried the following code so far, but it keeps opening the browser (I’m doing the tests in a Windows 10):

var webdriver = require('selenium-webdriver'),
        chrome    = require('selenium-webdriver/chrome')
        By        = webdriver.By,
        until     = webdriver.until,
        options   = new chrome.Options();
        options.addArguments('--headless');
    var path = require('chromedriver').path;
    var service = new chrome.ServiceBuilder(path).build();
        chrome.setDefaultService(service);
    var driver = new webdriver.Builder().forBrowser('chrome').withCapabilities(options.toCapabilities()).build();

driver.get('https://www.google.com');

Note that the addArguments(’–headless’) is the parameter that should make the navigation silent, but apparently it’s not working or I am missing something I am not aware of.

If there is something I am missing, please tell me because I don’t know if what I want to do is possible, as It is the frist time I work with this kind of technology.

Thanks.

1 Like

Try this one:

var webdriver = require('selenium-webdriver'),
    chrome    = require('selenium-webdriver/chrome')
    By        = webdriver.By,
    until     = webdriver.until,
    options   = new chrome.Options();
    options.addArguments('headless'); // note: without dashes
    options.addArguments('disable-gpu')
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
    chrome.setDefaultService(service);
var driver = new webdriver.Builder()
    .forBrowser('chrome')
    .withCapabilities(webdriver.Capabilities.chrome()) 
    .setChromeOptions(options)                         // note this
    .build();

driver.get('https://www.google.com');