Headless automation with Nodejs Selenium Webdriver

后端 未结 4 1663
眼角桃花
眼角桃花 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 19:10

    To start Chrome in headless mode, simply call Options.headless(). Starting in headless mode currently also disables GPU acceleration. This is the code:

      var seleniumWebdriver = require('selenium-webdriver');
      var chrome    = require('selenium-webdriver/chrome');
    
      var options   = new chrome.Options().headless();
    
      var driver = new seleniumWebdriver.Builder()
        .forBrowser('chrome')
        .setChromeOptions(options)
        .build();
    

    Note: For security, Chrome disables downloads by default when in headless mode. You may call setDownloadPath to re-enable downloads.

提交回复
热议问题