我想使用JS(TypeScript(更改chrome的默认下载目录。尝试设置这样的选项:
let options=webdriver。ChromeOptions;
options.add_argument("download.default_directory=C:/Downloads"(
let driver=webdriver.chrome(选项(;
但是,选项设置为未定义,并且网络驱动程序上不存在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();
}
根据此问题,chromeOptions键无法按预期工作。使用谷歌:chromeOptions设置chrome功能选项:
const chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set('goog:chromeOptions', {
'args': ['disable-infobars'],
'prefs': {
'download': {
'default_directory': '/home/{user}/Downloads/Chrome_test',
'prompt_for_download': 'false'
}
}
});
const 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();