Javascript 使用JS在webdriver中设置下载目录

Javascript 使用JS在webdriver中设置下载目录,javascript,selenium-webdriver,selenium-chromedriver,Javascript,Selenium Webdriver,Selenium Chromedriver,我想使用JS(TypeScript)更改chrome的默认下载目录。尝试设置如下选项: 让选项=webdriver.ChromeOptions options.add_参数(“download.default_directory=C:/Downloads”) 让driver=webdriver.chrome(选项) 但是,选项设置为未定义,并且webdriver上不存在ChromeOptions 以下是完整代码: let webdriver = require('selenium-webdriv

我想使用JS(TypeScript)更改chrome的默认下载目录。尝试设置如下选项:

让选项=webdriver.ChromeOptions

options.add_参数(“download.default_directory=C:/Downloads”)

让driver=webdriver.chrome(选项)

但是,选项设置为未定义,并且webdriver上不存在ChromeOptions

以下是完整代码:

let webdriver = require('selenium-webdriver');
let chrome = require('selenium-webdriver/chrome');
let chromedriver = require('chromedriver');

chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());

// let driver = new webdriver.Builder()
//     .withCapabilities(webdriver.Capabilities.chrome())
//     .build();
let options = webdriver.ChromeOptions;

options.add_argument("download.default_directory=C:/Downloads")

let driver = webdriver.chrome(options);

let figma = 'https://www.figma.com/';
driver.get (figma).then(
    backup
);

function backup() {
    driver.sleep(3000);
    driver.quit();
}

请尝试以下代码并让我知道:

var chrome = require('chromedriver');
var chromeCapabilities = webdriver.Capabilities.chrome();
const chromeOption = require('selenium-webdriver/chrome');
//setting chrome options to start the browser fully maximized
var chromeOptions = {
    'args': ['--test-type', '--start-maximized'],
    'prefs': {"download.default_directory":"/home/(user)/Downloads/Chrome_test"}
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder()
  .withCapabilities(chromeCapabilities)
  .build();

请尝试以下代码并让我知道:

var chrome = require('chromedriver');
var chromeCapabilities = webdriver.Capabilities.chrome();
const chromeOption = require('selenium-webdriver/chrome');
//setting chrome options to start the browser fully maximized
var chromeOptions = {
    'args': ['--test-type', '--start-maximized'],
    'prefs': {"download.default_directory":"/home/(user)/Downloads/Chrome_test"}
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder()
  .withCapabilities(chromeCapabilities)
  .build();
根据问题,chromeOptions键不能按预期工作。使用goog:chromeOptions设置chrome功能的选项:

const chromeCapabilities=webdriver.Capabilities.chrome();
chromeCapabilities.set('goog:chromeOptions'{
“args”:[“禁用信息栏”],
“prefs”:{
“下载”:{
“默认目录”:“/home/{user}/Downloads/Chrome\u test”,
'提示下载':'错误'
}
}
});
const driver=new webdriver.Builder()
.具有能力(色度能力)
.build();
根据问题,chromeOptions键无法正常工作。使用goog:chromeOptions设置chrome功能的选项:

const chromeCapabilities=webdriver.Capabilities.chrome();
chromeCapabilities.set('goog:chromeOptions'{
“args”:[“禁用信息栏”],
“prefs”:{
“下载”:{
“默认目录”:“/home/{user}/Downloads/Chrome\u test”,
'提示下载':'错误'
}
}
});
const driver=new webdriver.Builder()
.具有能力(色度能力)
.build();

在窗口中,由webdriver控制,我转到设置和保存位置,默认为:/home/elena/'X3азззззззззззззззззззззз,我去了设置,保存的位置是默认的:/home/elena/'3аззззззззззззззззззззз