CDP is an acronym for Chrome DevTools Protocol. Another name is Chrome Debugging Protocol.
In this chapter, I will introduce CDP, which is a new API feature that's built for the Chromium platform.
There are 2 browsers on the Chromium platform. Those 2 browsers are Google Chrome and Microsoft Edge. Both browsers have an option called Developer Tools.
If I go to Google Chrome and click these vertical ellipses, then navigate to More tools, we see an option called Developer tools.
It's the same with Microsoft Edge. If I go to Microsoft Edge, then click these horizontal ellipses, then navigate to More tools, we see an option called Developer tools.
When I click it, we see the usual panel we click and go to for inspecting an item. DevTools is short for Developer Tools.
Elements is the most popular tab for Selenium automation.
However, we also have Console, Sources, Network, Performance, Memory, Application, and Security.
We can take advantage of Chrome and Microsoft Edge's Debugging Protocol.
In the project, let's go to External Libraries, then navigate to Chromium Driver 4.0.
Expand the package for Chromium. Scroll down to ChromiumDriver.
Right click ChromiumDriver, then select Browse Type Hierarchy.
Now we see the parents of ChromeDriver and EdgeDriver starting with Object.
It will always be at the top because
Object is the superclass of all the classes.
Then we see RemoteWebDriver.
RemoteWebDriver is the parent to
Here's the update with Selenium 4 —
ChromiumDriver is now the parent to
With Selenium 3,
RemoteWebDriver was the parent to
For example, if I go to FirefoxDriver, expand, then go to the package. We see FirefoxDriver.
Now, if I do the same right click and go to Browse Type Hierarchy, we see
RemoteWebDriver as the parent to
RemoteWebDriver is also the parent to
ChromeDriver and EdgeDriver are the only 2 drivers that changed for Selenium 4 that now have ChromiumDriver as the parent.
Now, let's go back to the
When I open up
ChromiumDriver, we see it offers a lot of methods for
We will focus on 2 methods for CDP that allows us to control Developer Tools in Chrome and Edge.
One method is
executeCdpCommand. The purpose of
executeCdpCommand is to directly execute a Chrome DevTool Protocol command by passing in a parameter for that command.
We also have
GetDevTools as the second method.
Let's navigate to Selenium Remote Driver 4.0. Bingo.
If I open up this part and we see that if I expand the Selenium package, we see devtools, a class called
devtools, we have an interface called
This is the location of
getDevTools and it returns
DevTools is a class that has methods to handle developer options.
Next, we are going to view the browser console logs using