Search code examples
seleniumselenium-webdriverselenium-chromedriverdevtools

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.


Solution

  • 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:

    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.