Selenium 4 Chrome DevTools Examples

A few Selenium CDP examples in the Ruby language

Zhimin Zhan
4 min readOct 28, 2021

--

This article is included in my “How to in Selenium WebDriver” series.

Selenium WebDriver 4 supports Chrome DevTools Protocol(CDP), enabling a debugger inside Chromium-based browsers. By the way, Cypress and Puppeteer are based on CDP. CDP has some issues and limitations, not surprisingly, it is a debugging protocol after all.

In this article, I will show some DevTools examples with the new Selenium 4.

Table of Contents:· General
Navigate to a URL
Print to PDF
Get browser Client Size
Get browser info
Execute CDP Command
· Event
Console log messages
· Network
Basic Authentication
· Emulate
GEO Location
· Page
Download file
Navigation history
· Summary

While Selenium 4 supports CDP, it is not included by default. You need to install a separate gem ( ruby library):

> gem install — no-document selenium-devtools
Successfully installed selenium-devtools-0.94.0
1 gem installed

You will see the first limitation, CDP is associated with a particular version of Chrome. For example, I got the following error after the Chrome browser self-updated to v95.

Failure/Error…

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.