Manage Chrome Devtools with Selenium Webdriver

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

In particular, I want to use the "WASP" chrome plugin, accessed through devtools. I have my selenium configured to run with the WASP plugin enabled, and I can open DevTools (with sendKeys.F12), but I don’t know how to actually use this panel now when it is open. Is there any way to do this?

The closest I found to my problem is the link: Chrome Dev Tools and Selenium WebDriver API , but this did not help me at all,

Also, if it looks like it will be impossible (what is he doing), can anyone think of a workaround?

+6
source share
3 answers

Selenium 4 alpha has a way to interact with the DevTools API using the java client. In particular, you are looking for the Profiler domain ( https://chromedevtools.imtqy.com/devtools-protocol/tot/Profiler ).

I recently provided the Network and Performance domains for the best user API in Java Selenium - https://github.com/SeleniumHQ/selenium/pull/7212.

I believe that Profiler will also be implemented soon. Of course, there is a universal API for all domains in the Java client, which was merged some time ago, you can use it as follows:

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 is added to the Selenium Java client, you will need to provide your Mapper.

+1
source

The only thing you can do is to: - set focus to the dev tool window - get the URL of the dev tool window driver.url.toString (); - open a new tab with this URL

from there you can view the devtools window and can interact with various elements

if you cannot access elements that are below the shadow root level, then it is better to use an IJavascriptexecutor with something similar to this: return document.querySelector('element above shadow root').shadowRoot.querySelector('element below shadow root');

0
source

So I was able to use javascript to pass the requested item to the web driver and click on it. I used WinAppDriver to enter lines into the developer console to focus the window and enter the necessary command. It works moderately, but better than I expected.

0
source

Source: https://habr.com/ru/post/1232315/


All Articles