Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sendDevToolsCommand in Selenium 4 alpha

According to this article, Selenium 4 alpha has a sendDevToolsCommand that sends an arbitrary DevTools command to the browser and returns a promise that will be resolved when the command has finished:

Added “sendDevToolsCommand” and “setDownloadPath” for chrome.Driver.

But I can't seem to find how to use it. It sounds a bit like using JavaScript executor in Selenium.

Can someone provide an example usage? I'm using Selenium + Java.

like image 512
Mate Mrše Avatar asked Apr 16 '26 03:04

Mate Mrše


1 Answers

The command to call the devtool api was added a few years back in the Chrome driver.

You can already use it with Selenium even if the method is not yet present:

  • Take full page screenshot
  • Print To PDF
  • Inject some Javascript before the page loads
  • Block a network URL
  • Save/restore the cookies for all domains
  • Get transparent screenshot

This command gives you access to the devtools api, which is used by ChromeDriver internally to drive the browser.

The method takes the name of the command as first argument and a dictionary of parameters as second argument. To figure out how to call a command, add puppeteer in your searches. For instance puppeteer set download location.

Note that executeCdpCommand is implemented in the Java master branch, so it should be available in the next release.

like image 140
Florent B. Avatar answered Apr 19 '26 22:04

Florent B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!