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

标签 node.js selenium selenium-webdriver selenium-chromedriver

我想知道如何使用以下命令将我计算机上的解压扩展添加到我的 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/

相关文章:

ios - 通过node.js Rest API将图像从ios swift发布到postgres数据库

html - 如何找到框架集中元素的 XPath?

python - pip安装selenium权限错误

python - 如何使用变量 driver.find_element_by_id 的值

selenium-webdriver - 如何在c#上实现PhantomJS + Wedriver

node.js - 如何防止在 Express 的 REST api 调用中使用冲突的关键字

node.js - 尝试在 Node js 中初始化 Google Cloud api 时,无服务器失败

java - 无法单击 Selenium Webdriver 中的单选按钮

javascript - 等待链接点击 Selenium 的正确方法

javascript - 如何在 Node JS 中使用事件?