gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:59 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com