我正在尝试使用下面显示的代码添加具有 chrome 功能的默认下载路径:
const test = async () => {
let builder = await new Builder().forBrowser("chrome");
let chromeCapabilities = builder.getCapabilities();
// chromeCapabilities.set("download.default_directory", downloadFolder);
chromeCapabilities.merge({ "download.default_directory": downloadFolder });
console.log(chromeCapabilities.get("download.default_directory"));
// builder.setChromeOptions(chromeCapabilities);
builder.withCapabilities(chromeCapabilities);
// builder.setChromeOptions({ "download.default_directory": downloadFolder });
// builder.withCapabilities({ "download.default_directory": downloadFolder });
console.log(builder.getCapabilities().get("download.default_directory"));
const driver = builder.build();
await driver.get(tempoboxLoginUrl);
const driverCapabilities = await (await driver).getCapabilities();
console.log(await driverCapabilities.get("download.default_directory"));
};
test();
在将功能与我要添加的新功能合并后,我可以记录功能的值,它会按预期显示。但是,一旦构建了驱动程序,记录功能的值将返回 undefined。以下是使用 Node 运行此代码时的输出:
> node Test.js
C:\Users\dummy\Desktop << first log
C:\Users\dummy\Desktop << second log
DevTools listening on ws://127.0.0.1:57980/devtools/browser/d53946e4-cedc-4809-a20c-b8b3416463cc
undefined << third log