我想知道如何使用以下命令将我计算机上的解压扩展添加到我的 chrome webdriver 中: https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options.html#addExtensions 我真的不明白我应该用它做什么.. 预先感谢所有帮助我的人 =) P.S:我使用这些 Node 包:selenium-webdriver、fs
最佳答案
import {Builder, Capabilities} from 'selenium-webdriver';
import {Options, ServiceBuilder, setDefaultService} from 'selenium-webdriver/chrome';
import * as chromedriver from 'chromedriver';
import * as path from 'path';
import * as fs from 'fs';
const encodeExt = file => {
const stream = fs.readFileSync(path.resolve(file));
return Buffer.from(stream).toString('base64');
};
const service = new ServiceBuilder(chromedriver.path).build();
setDefaultService(service);
const driver = new Builder()
.withCapabilities(Capabilities.chrome())
.setChromeOptions(new Options()
.addExtensions(encodeExt('./3.5.2_0.crx'))) <-----+
.build(); |
|
|
this line here! ----------------------------
下载 .crx 文件的方法如下:https://www.maketecheasier.com/download-save-chrome-extension/
关于node.js - 从文件 Selenium node.js 添加解压的扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51182142/