【问题标题】:Selenium Webdriver Donwload file path (NodeJS)Selenium Webdriver 下载文件路径(NodeJS)
【发布时间】:2019-12-28 01:11:11
【问题描述】:

我正在尝试为 Chrome 浏览器设置下载位置,但我卡住了。

const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

const chromeOptions = new chrome.Options();
chromeOptions.set('download.default_directory', __dirname + '/download');

const builder = await new Builder()
    .forBrowser('chrome')
    .setChromeOptions(chromeOptions)
    .build();

我做错了什么或者传递我自己的下载文件夹的正确方法是什么?

非常感谢!!

【问题讨论】:

标签: node.js selenium selenium-webdriver


【解决方案1】:

我终于知道了。

const { Builder } = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')

const chromePrefs = { 'download.default_directory': __dirname + '/download' }
const chromeOptions = new chrome.Options().setUserPreferences(chromePrefs)

const driver = await new Builder()
  .forBrowser('chrome')
  .setChromeOptions(chromeOptions)
  .build()
  .catch(e => console.error(e))

在 NodeJS 中 setUserPreferences 不再是实验性的!

【讨论】:

  • 谢谢伙计。你救了我的命。我花了半天时间试图弄清楚。
猜你喜欢
  • 2014-05-08
  • 1970-01-01
  • 1970-01-01
  • 2020-10-24
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多