簡體   English   中英

Selenium Webdriver下載文件路徑(NodeJS)

[英]Selenium Webdriver Donwload file path (NodeJS)

我正在嘗試為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();

我做錯了什么或者傳遞自己的下載文件夾的正確方法是什么?

非常感謝!!

我終於找到答案了

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不再具有實驗性!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM