Headless automation with Nodejs Selenium Webdriver

后端 未结 4 1662
眼角桃花
眼角桃花 2021-01-30 18:30

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.

4条回答
  •  再見小時候
    2021-01-30 18:54

    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');
    

提交回复
热议问题