从文件SeleniumNode.js添加解压缩扩展名



我想知道如何使用以下方法将我在计算器上的解压缩扩展添加到我的chrome Web驱动程序中: https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options.html#addExtensions 我真的不明白我应该用它做什么.. 提前感谢所有对我有帮助的人=( P.S : 我使用这些节点包:硒网络驱动程序,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/

你可以这样做:

let chrome = require("selenium-webdriver/chrome");
let options = new chrome.Options();
options.addExtensions("/path/to/extension.crx")
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

其他 2 个答案需要打包扩展名 (.crx(。

对于解压缩的扩展,请改用以下内容:

const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
let opt = new chrome.Options();
opt.addArguments("--load-extension=/path/to/extension");
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(opt)
.build();

下面是 C# 的类似答案:https://stackoverflow.com/a/18994520

最新更新