提问人:Mercu Kevin 提问时间:10/30/2023 最后编辑:Mercu Kevin 更新时间:10/30/2023 访问量:20
如何使用“nodejs”在 Selenium 中处理自签名证书弹出窗口?
How to Handle Self-Signed Certificate Pop-up in Selenium using "nodejs?"
问:
我以这篇文章为指导:这是一个 java 版本,我掌握了文章的想法,但无法使用 nodejs 实现......
喜欢: 主线:
When('getToURL', { timeout: 1120000 }, async function () {
const openBrowserProcess = child_process.fork('./openBrowser.js');
const pressEnterProcess = child_process.fork('./pressEnter.js');
openBrowserProcess.send(driver);
pressEnterProcess.send(driver);
});
打开浏览器,.js:
process.on('message', async (driver) => {
try {
await driver.get('https://.........');
} catch (error) {
console.error(error);
}
});
按 Enter:.js:
const robot = require('robotjs');
// Receive the driver instance from the main thread
process.on('message', async (driver) => {
try {
// Simulate waiting for the self-signed popup
await sleep(5000);
// Simulate pressing the "Enter" key using RobotJS
robot.keyTap('enter');
} catch (error) {
console.error(error);
}
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
我尝试过 worker_threads / child_process,但都遇到了一些问题......有人可以帮助我吗?多谢!
答: 暂无答案
评论