使用Selenium Webdriver控制Chrome Devtools [英] Controlling Chrome Devtools with Selenium Webdriver

查看:1792
本文介绍了使用Selenium Webdriver控制Chrome Devtools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过Selenium Webdriver访问/使用Chrome的devtools面板.

I am looking to access/use Chrome's devtools panel with Selenium Webdriver.

具体来说,我想使用通过devtools访问的"WASP" chrome插件.我已经设置好硒,使其可以与WASP插件一起运行,并且可以打开DevTools(带有sendKeys.F12),但是现在不知道如何实际使用该面板.有办法吗?

Specifically, I want to use the "WASP" chrome plugin, which is accessed through devtools. I've got my selenium set up to run with the WASP plugin included, and I can open DevTools (with sendKeys.F12), but I don't know how to actually use that panel now that it is open. Is there a way to do so?

我发现最接近问题的是此链接: Chrome开发工具API和Selenium WebDriver ,但这对我完全没有帮助.

The closest thing I've found to my problem is this link: Chrome Dev Tools API & Selenium WebDriver, but that hasn't been helpful at all to me.

此外,如果看起来这不可能(确实如此),谁能想到解决方法?

Also, if it looks like this will be impossible (which it does) can anyone think of a workaround?

推荐答案

在Selenium 4 alpha中,有一种使用Java客户端与DevTools API进行交互的方法.您正在寻找的是"Profiler"域( https://chromedevtools.github .io/devtools-protocol/tot/Profiler )

In Selenium 4 alpha, there is a way to interact with DevTools API using the java-client. What you are looking for specifically is the "Profiler" domain (https://chromedevtools.github.io/devtools-protocol/tot/Profiler)

最近,我为硒Java中更好的面向用户的API贡献了网络"和性能"域-

Recently, I contributed the "Network" and "Performance" domains for a better user facing API in selenium java - https://github.com/SeleniumHQ/selenium/pull/7212

我相信"Profiler"也将很快实施.当然,Java客户端中的所有域都有一个通用的API,它已经合并了一段时间,您可以像这样使用它:

I believe that "Profiler" will also be implemented soon. Of course, there is a generic API for all domains in Java client that was merged a while ago, you can use it like this:

     driver.getDevTools().createSession();

    driver.getDevTools().send(new Command("Profiler.enable", ImmutableMap.of()));
    driver.getDevTools().send(new Command("Profiler.start", ImmutableMap.of()));

    //register to profiler events
    driver.getDevTools().addListener(new Event("Profiler.consoleProfileStarted", ConsoleProfileStarted.class), new Consumer<Object>() {
        @Override
        public void accept(Object o) {
            //do something
        }
    });

在Profiler域添加到Selenium Java客户端之前,您将必须提供Mapper.

Until the Profiler domain will added to Selenium java client, you will have to supply your Mapper.

这篇关于使用Selenium Webdriver控制Chrome Devtools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆