Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling Chrome Devtools with Selenium Webdriver

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

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?

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?

like image 857
Sarah Avatar asked Sep 25 '15 21:09

Sarah


People also ask

How do I access Chrome developer tools in selenium?

Chrome Developer Tool is available for Chrome and Chromium-based browser you can invoke this developer tool by using keyboard shortcut CTRL + SHIFT + I or F12, you can also invoke from User interface in Chrome Browser.

Does selenium use CDP?

Selenium 4 uses Chrome Debugging Protocol (CDP) to achieve event-driven testing with the help of the following features: Listen to console log events. Listen to JS exceptions. Intercept network.

Does selenium WebDriver work with Chrome?

Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, and Safari. Where possible, WebDriver drives the browser using the browser's built-in support for automation.

How do I inspect Developer Tools in Chrome?

One of the easiest ways to inspect a specific web element in Chrome is to simply right-click on that particular element and select the Inspect option. Clicking on the Inspect option from the right-click menu will directly open the Developer tools including the editor, Console, Sources, and other tools.


1 Answers

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)

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

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
        }
    });

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

like image 119
Adi Ohana Avatar answered Oct 05 '22 07:10

Adi Ohana