selenium-webdriver在节点中传递chrome参数

时间:2017-09-22 18:44:34

标签: google-chrome selenium

我在节点中使用selenium:

require('chromedriver');

var webdriver = require('selenium-webdriver'), By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
  .forBrowser('chrome')
  .build();

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

有没有办法如何传递命令行参数并使用无头模式启动chrome隐藏?

如何?

1 个答案:

答案 0 :(得分:0)

你需要这样做

require('chromedriver');

var webdriver = require('selenium-webdriver'), By = webdriver.By,
    until = webdriver.until,  chrome = require("selenium-webdriver/chrome");

var driver = new webdriver.Builder()
  .forBrowser('chrome')
  .setChromeOptions(new chrome.Options().headless())
  .build();

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