从文件 Selenium node.js 添加解压的扩展

Zay*_*onx 4 selenium node.js selenium-chromedriver selenium-webdriver

我想知道如何使用以下命令将计算机上的解压扩展添加到 chrome webdriver 中:https: //seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options .html#addExtensions 我真的不明白我应该用它做什么。提前感谢所有帮助我的人 =) PS:我使用这些节点包:selenium-webdriver、fs

Mos*_*ntz 5

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! ----------------------------
Run Code Online (Sandbox Code Playgroud)

这是下载 .crx 文件的方法:https://www.maketecheasier.com/download-save-chrome-extension/