Selenium WebDriver 4
What’s New???
Vikas Thange
Test Architect Nov 16, 2021
3.x
v3.0 - Oct 2016
v3.141.59 - Nov 2018
4.x
Alpha - April 2019
Beta - Feb 2021
Release Candidate - Sep 2021
Stable - Oct 2021
4000+ Commits
3.x
The JSON Wire Protocol
– Facilitated communication between test code
and the browser in question
– Involved the unnecessary extra task of
encoding and decoding API requests via the
W3C protocol
– Only drivers used W3C webdriver protocol
– WebDriver utilizes the W3C standardization.
– Now WebDriver communicate directly with the
driver without JSON wire protocol encoding
decoding
– This will likely result in more stable cross
browser tests via Selenium than in its previous
architectures.
– The JSON Wire Protocol will be deprecated in
Selenium 4
– Opera & PhantomJS native support removed
4.x
Architectural difference
Selenium 3 Selenium 4
source:https://blog.testproject.io/2021/10/15/selenium-4-is-officially-released/
4.x
➢ Selenium WebDriver W3C Standardization
➢ Enhanced Selenium 4 IDE
➢ RemoteWebDriver Builder
➢ DesiredCapabilities
➢ Relative Locators
➢ Page Printing Test
➢ New Window handling API
➢ Basic & Digest Authentication
➢ Support for Chrome DevTools
➢ DOM Mutation
➢ Read Console Message
➢ Capture JS Errors
➢ Network Interceptions
➢ Optimized Selenium Grid
○ Re-Architectured for future
○ Observability
○ Improved Scalability (Docker & k8s support)
○ + More
➢ The shadow DOM automation
New Features / Changes
Selenium WebDriver W3C Standardization
https://www.w3.org/TR/webdriver/
JSON Wire Protocol
Mar 10, 2018 https://www.youtube.com/channel/vikasthange https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
Selenium WebDriver W3C Standardization
Selenium WebDriver W3C Standardization
RemoteWebDriver Instance
Selenium 3
RemoteWebDriver Builder
Selenium 4 - Local
RemoteWebDriver Builder
Selenium 4 - Remote machine
DesiredCapabilities
In Selenium 4, DesiredCapabilities have been replaced by Options. To use the Driver class, QAs
have to create an Options class object, set test requirements, and pass the object to the Driver
constructor.
Driver constructors that accepted Capabilities objects have been replaced with those that accept
Options.
# ChromeDriver(Capabilities) replaced by ChromeDriver(ChromeOptions).
# SafariDriver(Capabilities) replaced by SafariDriver(SafariOptions).
# EgdeDriver(Capabilities) replaced by EdgeDriver(EdgeOptions).
# FirefoxDriver(Capabilities) replaced by FirefoxDriver(FirefoxOptions).
# InternetExplorerDriver(Capabilities) replaced by InternetExplorerDriver(InternetExplorerOptions).
DesiredCapabilities
Relative Locator
Relative Locator
Relative Locator
Relative Locator
- All in for Relative Locators?? Nah!!
- Not recommended as a replacement of primary locators
- Be careful while using Relative Locators if you expect elements positions to
change
- Dynamic element locators and no unique locator could be good usecase for
Relative Locators
Page Printing Test
New Window Handling API
Basic & Digest Authentication - Event Driven
Chrome Debugging Protocol (CDP) support
- Automate Chromium based browsers
- Access Advanced features from browser
- Interfact HasDevTools
- Not recommended as It’s ties tests to specific browser / Version.
Chrome Debugging Protocol (CDP) support
Read Console Messages
Capture JavaScript Errors
Network Interceptions
Selenium Grid
Observability
Event driver
Docker &
K8s support
Appium Support
The shadow DOM
No Major changes - Backward compatibility
Actions API
WebDriver Wait / Fluent wait
8 Primary locators
WebElements methods
WebDriver methods
Summary
- Selenium 3 has already matured with all required features needed for
automation.
- Upgrade 4 is majorly w3c standardization. However it is a big upgrade
architecturally , at end user we might not see the difference in code. The
capabilities / API calls will be automatically handled by client libs.
- New features added are more advanced features. Just like addons and may
not be needed really needed by every team
- Use of Relative locators and CDP tools are not recommended by selenium
Devs.
- Support for shadow dom automation may open door to automating complex
apps
References
https://applitools.com/event/using-selenium-4/
https://www.browserstack.com/webinars/selenium-4-whats-new-and-how-you-can-
use-it
https://blog.testproject.io/2021/10/15/selenium-4-is-officially-released/
https://medium.com/@vikasthange/browserstack-browsermob-proxy-for-network-
call-intercepting-11c4bf77a376
https://www.lambdatest.com/learning-hub/selenium-4
Source code https://gitlab.com/vikasthange/selenium-4-latest-features-demo-code/-
/tree/main/src/test/java
Q&A
Thank You

Selenium webdriver version 4 features by vikas thange xpanxion automation test architect