使用selenium包,进行web自动化测试;重定向问题(browser-proxy包使用)

使用语言为nodejs

操作selenium包时,发现网页总是一闪而过,后来发现时oauth2框架编写的;也就是网页点击后,会进行网页重定向,产生键值对;即访问:www.xxx.com;实际会重定向到www.xxx.com/#?key=value等等;

百度搜索基本上都是通过browser-proxy拦截获取network的数据流,然后读取留,截取实际的网页,在进行访问;实际在多次下载包后,仍然无法使用,纠结一周了;

目前实践的情况
1、下载browsermob-proxy-2.1.4成功,可以运行批处理,是单独的小黑窗CMD;可以运行,发现默认代理8080;下载chrome驱动也成功,也配置了全局变量;
2、使用selenium

let webdriver = require('selenium-webdriver');
let chrome = require('selenium-webdriver/chrome');
let proxy = require('selenium-webdriver/proxy');
let opts = new chrome.Options();
    (async function example() {
        opts.setProxy(proxy.manual({ http: '<localhost:8080>' }));
        let base_url = "http://www.baidu.com"
        let driver = new webdriver.Builder()
            .forBrowser('chrome')
            .setChromeOptions(opts)
            .build();
        try {
            await driver.get(base_url);
            let title1 = await driver.getTitle();
            console.log(title1)
        }
        finally {
            await driver.quit();
        }
    }());

总是报错:Invalid 'main' field in 'D:\Fluduo\codeplay\project\Y2021\node_modules\browsermob-proxy\package.json' of './browsermob.js'. Please either fix that or report it to the module author
(估计是版本被depressed?要么是方法被弃用,要么就是不是个函数,哎,折磨啊)

总是无法获取到 .har 文件,这个是第三步。求解答。

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。