What Is New In Selenium 4 And What Is Deprecated In It?
Himanshu Sheth
Posted On: April 15, 2025
192989 Views
19 Min Read
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium 4.
Selenium 4 brings some exciting updates and architectural changes, making it a game-changer for automation testers and developers. With full W3C standardization, it ensures smoother, more reliable communication between the client and browser.
The improved debugging features, including seamless integration with Chrome DevTools Protocol, make it easier to track performance and network activity. Plus, the revamped Selenium Grid offers better scalability and simpler deployment, helping teams run distributed tests more efficiently.
These enhancements come together to deliver a more stable and high-performing automation solution for modern workflows.
TABLE OF CONTENT
- What Is New in Selenium 4?
- Key Improvements Introduced in Selenium 4
- Selenium WebDriver W3C Standardization
- Improved and Optimized Selenium Grid
- Enhanced Selenium 4 IDE
- Simplification to Open New Browser Windows and Tabs
- Relative Locators
- Capturing Screenshots in Selenium 4
- Chrome DevTools
- Monitoring in Selenium 4
- Enhanced Documentation
- Key Enhancements to the Actions Class in Selenium 4
- Click()
- DoubleClick() and ContextClick()
- ClickAndHold() and Release()
- dragAndDrop()
- pause()
- keyDown() / keyUp() Over WebElement
- Key Modifications to the ‘FluentWait’ Class in Selenium 4
- Removed and Deprecated Functionality in Selenium 4
- Selenium 3 Vs Selenium 4 – The Final Showdown
- Frequently Asked Questions (FAQs)
What Is New in Selenium 4?
Selenium 4 introduces several exciting features and enhancements. The most significant update is the full W3C compliance of WebDriver APIs, ensuring more stable and less error-prone cross-browser testing.
One of the standout additions is WebDriver BiDi (Bidirectional Protocol) support. This enables real-time, two-way communication between the browser and the test script, unlocking powerful capabilities like console log monitoring, network interception, and more dynamic debugging and automation features, previously only available through tools like Chrome DevTools Protocol (CDP).
In addition to this, relative locators have been introduced, allowing for more intuitive element identification using terms like above(), below(), toLeftOf(), and near(), making locators easier to maintain.
The Selenium Grid has also been revamped, making it more scalable and reliable with native support for Docker and Kubernetes, simplifying test distribution and execution in CI/CD pipelines.
Furthermore, the Selenium IDE has been improved for better usability, cross-browser support, and plugin flexibility, enhancing the overall test creation experience.
To get started with Selenium 4, download the stable release for your preferred language:
Language | Selenium 4 Download Links |
---|---|
Selenium 4 for Java | https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.31.0/selenium-java-4.31.0.zip |
Selenium 4 for Python | https://pypi.python.org/pypi/selenium |
Selenium 4 for C# | https://www.nuget.org/packages/Selenium.WebDriver |
Selenium 4 for Ruby | https://rubygems.org/gems/selenium-webdriver/versions/4.31.0 |
Key Improvements Introduced in Selenium 4
Below are some of the significant changes that you will experience with Selenium 4:
Selenium WebDriver W3C Standardization
In Selenium’s earlier versions (i.e., Selenium 3), the JSON Wire Protocol was responsible for communication between the web browser and the test code. This led to the additional overhead of encoding and decoding the API requests using the W3C protocol.
This is set to change with WebDriver in Selenium 4, as the WebDriver APIs adopt the W3C standardization.
Since major browser drivers, such as geckodriver, chromedriver, etc., follow the W3C standard, the WebDriver in Selenium 4 will directly communicate with the web browser.
Selenium vs. WebDriver W3C protocol has co-existed along with JSON Wire Protocol; it will be the default protocol in Selenium 4. JSON Wire Protocol will be deprecated in Selenium 4.
Selenium 4 no longer supports Opera and PhantomJS, as their WebDriver implementations are no longer being developed. Users can instead test on Chromium-based Chrome for Opera or use headless Firefox and headless Chrome as alternatives for PhantomJS testing.
WebDriver W3C Protocol is the biggest architectural change that will take effect in Selenium 4, and WebDriver W3C standardization will result in more stable cross-browser tests than the previous releases of Selenium!
Improved and Optimized Selenium Grid
The Selenium Grid for distributed test execution has evolved from the traditional Hub-Node architecture. In Selenium 4, the Hub and Node components are now packaged in a single JAR file, simplifying the setup.
The server acts as both a Hub and a Node, making configuration and scaling more straightforward. Previously, the Selenium Grid supported only Router, Session Map, and Distributor processes. In Selenium 4, these are complemented by the Node process, offering more scalability and traceability in the infrastructure.
Now supporting IPv6 and HTTPS, Selenium Grid 4 allows for more secure and robust communication. Additionally, configuration files are now easier to manage using the TOML (Tom’s Obvious, Minimal Language) format, which simplifies the setup process with a human-readable configuration file.
The user interface has been significantly improved, making the grid more intuitive and user-friendly. Enhanced support for Docker in Selenium Grid can now be deployed easily in Virtual Machines (VMs), while users can also leverage Kubernetes for dynamic scaling.
This integration streamlines the DevOps workflow, particularly when working with tools such as AWS and Azure. Selenium Grid 4’s cloud compatibility allows for more flexible testing in modern CI/CD pipelines.
The Selenium community remains excited about these updates, as they represent a leap forward in making grid management more scalable, flexible, and intuitive for testing automation.
Run Selenium 4 tests across 5000+ real desktop browsers. Try LambdaTest Now!
Enhanced Selenium 4 IDE
Automation test engineers familiar with record and playback testing would have come across the Selenium IDE. It is a simple turn-key solution that is web-ready and works out of the box. Selenium IDE, which was earlier available only as a Firefox extension, did not have many exciting features.
With Selenium 4, the Selenium IDE is finally ‘useful,’ as it is available for major web browsers like Chrome and Firefox. The plugin (or web extension) for Selenium IDE is now available on the Microsoft Edge Store, alongside Chrome and Firefox.
The Selenium IDE can be used to create better tests, as it supports a control-flow mechanism (i.e., usage of if..else, while, etc.).
Along with a shiny and user-friendly user interface, Selenium IDE in Selenium 4 also comes with a SIDE tool (Selenium IDE Runner) that lets you run a .side project on a Node.js platform.
The SIDE Runner can execute cross-browser tests in parallel, either on a local Selenium Grid or a cloud-based Selenium Grid like LambdaTest.
The backup element locator strategy is followed in scenarios where the web element cannot be located using the specified element locator. This makes the tests executed on the Selenium IDE more stable and reliable.
The automation tests recorded using the Selenium IDE can now be exported as code for all official language bindings like Java, C#, Python, .NET, and JavaScript.
This can be useful for black-box testers who want to enter the field of automation testing but have limited implementation knowledge in Selenium. The configuration files (in the .yml format) used by the SIDE runner can be easily customized to realize parallel testing on the Selenium IDE.
Simplification to Open New Browser Windows and Tabs
There are a number of scenarios where you would want to open a new browser window or tab and perform a certain set of actions in the newly opened window/tab.
In Selenium 3, you had to create a new WebDriver object and then switch to the new window or tab using its unique WindowHandle to perform subsequent actions.
Selenium 4 provides a new API, newWindow(), that lets you create a new window or tab and automatically switch to it. Since the new window or tab is created in the same session, it avoids creating a new WebDriver object.
- To create a new tab in Selenium 4 and switch to it, pass WindowType.TAB to the newWindow() method.
- To create a new window in Selenium 4 and switch to it, pass WindowType.WINDOW to the newWindow() method.
Each browser window in Selenium has a unique WindowHandle (or ID). The required WindowHandle should be passed to the switchTo(). The window() method to switch between the different windows.
- Open a New Window in Selenium 4
- Open a New Tab in Selenium 4
1 2 3 4 5 |
driver.get("https://www.google.com/"); // Opens a new window and switches to the new window driver.switchTo().newWindow(WindowType.WINDOW); // Opens LambdaTest homepage in the newly opened window driver.navigate().to("https://www.lambdatest.com/"); |
1 2 3 4 5 |
driver.get("https://www.google.com/"); // Opens a new tab and switches to the new tab driver.switchTo().newWindow(WindowType.TAB); // Opens LambdaTest homepage in the newly opened tab driver.navigate().to("https://www.lambdatest.com/"); |
Relative Locators
In Selenium 3, there were no shortcuts (or specific methods) to locate WebElements relative to nearby elements. With the release of Selenium 4, relative locators (also called Friendly locators) make it easier to locate WebElements based on their visual location relative to other DOM elements.
Relative locators help locate WebElements that are near, to the left of, to the right of, above, or below a specified element. These locators can be used with methods like withTagName in Selenium 4 Java or with_tag_name in Selenium 4 Python.
Here are the five relative locators that are available in Selenium 4:
Relative Locator | Description |
---|---|
above | The required WebElement is above a specified element. |
below | The required WebElement is below a specified element. |
to_left_of | The required WebElement is to the left of a specified element. |
to_right_of | The required WebElement is to the right of a specified element. |
near | The required WebElement is at most 50 pixels away from the specified element. |
To learn how to use relative locators to locate WebElements relative to a specified element in the DOM, you can refer to our earlier blogs on Selenium 4 Relative Locator and Selenium 4 for Python.
Capturing Screenshots in Selenium 4
In Selenium 3, there was an option to capture a screenshot of the entire web page. However, in Selenium 4, a new feature allows you to capture screenshots of specific WebElements.
This eliminates the need for third-party tools like Shutterbug or Ashot (which were previously used in Selenium 3) for capturing screenshots of individual WebElements.
Selenium 4 introduces a method that captures a screenshot of a particular element in the current browsing context.
The screenshot returned by the WebDriver endpoint is encoded in Base64 format.
Here’s how you can capture a WebElement screenshot in Selenium 4 (for Java):
In the implementation above, we capture the screenshot of the “login button” WebElement on the LambdaTest Sign-in page.
Chrome DevTools
Selenium 4 provides native support for the Chrome DevTools Protocol through the ‘DevTools’ interface. As the name indicates, the support is available only for the Chrome browser. CDP tools are used to get Chrome Development properties such as Fetch, Application Cache, Network, Performance, Profiler, and more.
Chrome DevTools, a set of web developer tools, provides APIs through which QA engineers and developers can edit pages on-the-fly and diagnose issues faster.
These operations help in making websites efficient and quicker. Chrome DevTools APIs can be used for emulating geolocation and emulating network conditions. We have covered the following topics in Selenium 4 in greater detail:
- Emulate Geolocation and Network Conditions in Selenium 4 Python
- Emulating Geolocation in Selenium 4 with Java
Native support for Chrome DevTools Protocol through the DevTools interface is one of the promising Selenium 4 Features that would help optimize websites through features like geolocation testing, emulating (or faking) different network conditions, and more.
You can also refer to the tutorial below on how to perform responsive testing using Chrome Dev Tools protocol in Selenium 4.
Monitoring in Selenium 4
Selenium 4 introduces significant optimizations to logging and request tracing processes. These improvements are designed to accelerate the debugging process, providing better insights during test execution.
With enhanced monitoring, testers can now quickly identify and address issues, resulting in more efficient test development and ultimately higher-quality test scripts.
Enhanced Documentation in Selenium 4
The official documentation of Selenium 4 is exhaustive, and the content layout makes it easy to reach the desired information in a few clicks. The enhanced documentation helps users understand how new features (and APIs) in Selenium 4 can be used in test code.
Selenium 4 documentation covers all aspects of Selenium Grid 4, Selenium IDE, and the WebDriver W3C protocol. Automation testers can use the documentation to get acquainted with the new APIs offered by Selenium 4. Start free testing, run your Selenium IDE tests on the cloud.
Key Enhancements to the Actions Class in Selenium 4
Actions Class in Selenium provides several methods for performing a single action or a series of actions on the WebElements present in the DOM. Mouse actions (e.g., click, double click, etc.) and Keyboard actions (e.g., keyUp, keyDown, sendKeys) are the two broad categories of Actions.
For demonstration, you will port the examples demonstrated in the Action class in Selenium blog from Selenium 3 to Selenium 4.
With Selenium 4, new methods are added to the Actions class, which replaces the classes under the org.openqa.selenium.interactions package.
Click()
click(WebElement) is the new method added to the Actions class, and it serves as the replacement of moveToElement(onElement).click() method.
Example:
DoubleClick() and ContextClick()
Below is the definition and example of how to use DoubleClick and ContextClick in Selenium 4.
- DoubleClick(): The method moveToElement(element).doubleClick(), used for double-clicking on a WebElement, is replaced with a doubleClick(WebElement) method in Selenium 4.
- ContextClick(): The method moveToElement(onElement).contextClick(), used for right-clicking on a WebElement, is now replaced with the contextClick(WebElement) method in Selenium 4.
Example:
We demonstrate the usage of DoubleClick() along with the ContextClick() method.
ClickAndHold() and Release()
Below is the definition and example of how to use ClickAndHold() and release() in Selenium 4.
- ClickAndHold(): The method moveToElement(Element).clickAndHold() used for clicking on a WebElement without performing the Release action is replaced with clickAndHold(WebElement).
- release(): The release() method, which is used for releasing the pressed mouse button, has been a part of the org.openqa.selenium.interactions.ButtonReleaseAction class. In Selenium 4, the method is a part of the Actions class.
Example:
We demonstrate the usage of ClickAndHold() along with the release() method.
dragAndDrop()
In Selenium 3, the dragAndDrop() method had limited support across all browsers, especially when simulating drag actions on complex HTML5 elements. Selenium 4 improves this functionality with enhanced compatibility and reliability, particularly when combined with modern WebDriver implementations.
Example:
pause()
The pause() method is newly introduced in Selenium 4 to insert an intentional wait between two chained actions. This is useful when simulating realistic user interactions or waiting for intermediate UI updates.
Example:
keyDown() / keyUp() Over WebElement
In Selenium 3, keyDown() and keyUp() were commonly applied without specifying the element. Selenium 4 allows these methods to be used with specific WebElements, offering better targeting for complex keyboard interactions.
Example:
To explore the complete list of new features and improvements in Selenium 4, watch the detailed video tutorial below.
Subscribe to the LambdaTest YouTube Channel to get more videos tutorials around what is Selenium , Selenium ChromeDriver and much more.
Key Modifications to the ‘FluentWait’ Class in Selenium 4
FluentWait in Selenium is used for performing a Selenium wait for an element when there is no certainty of the time it would take to be visible or clickable.
As seen in the FluentWait in Selenium example (with Selenium 3), the withTimeout() method takes two parameters int and TimeUnit.
1 |
.withTimeout(60, SECONDS) // this defines the total amount of time to wait for |
The pollingEvery() method takes two parameters – int and TimeUnit (e.g. SECONDS).
1 |
.pollingEvery(2, SECONDS) // this defines the polling frequency |
Example
With Selenium 4, the methods withTimeout() and pollingEvery() that are a part of the FluentWait class have been modified.
- The pollingEvery() method now accepts only one parameter – Duration.
- The withTimeout() method also takes only one parameter – Duration.
- Chrome: ChromeOptions
- Firefox: FirefoxOptions
- Internet Explorer (IE): InternetExplorerOptions
- Safari: SafariOptions
- Microsoft Edge: EdgeOptions
- LambdaTest: LTOptions (nested inside the browser-specific Options using “LT:Options” key)
- ChromeDriver (Selenium 3) 🡪 ChromeOptions (Selenium 4)
- FirefoxDriver (Selenium 3) 🡪 FirefoxOptions (Selenium 4)
- IEDriver (Selenium 3) 🡪 InternetExplorerOptions (Selenium 4)
- SafariDriver (Selenium 3) 🡪 SafariOptions (Selenium 4)
- EdgeDriver (Selenium 3) 🡪 EdgeOptions (Selenium 4)
- WebDriverBiDi: https://www.selenium.dev/documentation/webdriver/bidi/
- Selenium 4.29 Released: https://www.selenium.dev/blog/2025/selenium-4-29-released/
- Removing ChromeDevTools Support For Firefox: https://www.selenium.dev/blog/2025/remove-cdp-firefox/
Example:
Improvements You Can Leverage in Selenium 4
Selenium 4 supports Java 8 lambdas, allowing you to write more concise and readable FluentWait conditions. You can also use FluentWait generically with elements other than WebDriver.
Use Lambda for Cleaner Code:
Selenium 4 is fully compatible with Java 8+ features like lambdas, making the condition block shorter and easier to read.
1 |
WebElement foo = fluentWait.until(driver -> driver.findElement(By.id("foo"))); |
Note: FluentWait remains under the org.openqa.selenium.support.ui package. It is a generic class, so you can also use it with types other than WebDriver, e.g., WebElement. For more details follow this official Selenium documentation on FluentWait.
Removed and Deprecated Functionality in Selenium 4
As Selenium 4 keeps evolving, it introduces exciting new features and functionalities, but it also deprecates and alters several existing ones.
If you’re upgrading from Selenium 3, these changes might affect your test scripts.
Here, you will explore the specific deprecations and changes in Selenium 4, highlighting what’s no longer supported, what’s new, and how to handle the transition with practical code examples.
Deprecation of Desired Capabilities
In Selenium 3, we made extensive use of DesiredCapabilities when working with a RemoteWebDriver. This was essential for setting browser capabilities to run tests on a cloud-based Selenium Grid like LambdaTest.
However, with Selenium 4, DesiredCapabilities is deprecated.
In Selenium 4, Capabilities objects are replaced with browser-specific Options, and we now create an Options object and pass it directly to the Driver constructor. This object includes all necessary test requirements (e.g., browser and OS combinations).
Henceforth, the following Options objects should be used for setting browser-specific capabilities:
LambdaTest is an AI-native test execution platform that allows you to run manual and automated tests at scale across 5000+ real devices, browsers, and OS combinations.
It integrates seamlessly with Selenium 4, making it ideal for cross-browser and cross-platform testing at scale.
When running tests on LambdaTest with Selenium 4, you should configure a Map
This map should be added as a nested capability using the key “LT:Options” inside the appropriate browser-specific Options object (e.g., ChromeOptions, FirefoxOptions) before initializing the RemoteWebDriver.
Example:
Here are the examples that demonstrate the usage of the ‘Options’ object for setting browser capabilities:
a. Cloud-based Selenium Grid
b. Local Selenium Grid
a. Cloud-based Selenium Grid
b. Local Selenium Grid
a. Cloud-based Selenium Grid
b. Local Selenium Grid
a. Cloud-based Selenium Grid
b. Local Selenium Grid
a. Cloud-based Selenium Grid
b. Local Selenium Grid
The FindsBy Method
In Selenium 4, the FindsBy interfaces, previously part of the org.openqa.selenium.internal package, have been deprecated.
However, the core methods for locating elements—findElement(By) and findElements(By), remain unchanged and can continue to be used as in Selenium 3.
You can still use findElement() and findElements() with various locators like By.id, By.name, By.xpath, and more.
Example of using findElement in Java:
Example of using findElements in Java:
Selenium 3 Vs Selenium 4 – The Final Showdown
When it comes to the Selenium 3 vs Selenium 4 comparison, the introduction of the WebDriver W3C protocol is one of the significant architectural changes that will redefine the Selenium framework experience.
Apart from this significant under-the-hood change, other great Selenium 4 features such as the introduction of relative locators, Selenium Grid and its optimization, super-useful Selenium IDE (on Chrome and Firefox), and native support for the CDP (Chrome DevTools) protocol make the Selenium 4 experience much better in comparison to Selenium 3.
If you are still using Selenium 3 and want to upgrade to Selenium 4, follow this detailed guide on how to upgrade from Selenium 3 to Selenium 4.
Conclusion
To make the most out of the Selenium 4 features, it is recommended to perform testing on a scalable and reliable cloud-based Selenium 4 Grid like LambdaTest to execute in parallel across different browser and OS combinations. With this approach, you can perform geolocation testing on the Selenium 4 Grid in 170+ different countries.
Though Selenium 4 is still in the stages, the newly introduced features help accelerate testing activities, which were not possible with Selenium 3.
Have you tried Selenium 4 ? If yes, do let us know what features you liked the most, along with the overall experience of working with Selenium 4!
Also, if you’re looking to improve your Selenium interview skills, check out our curated list of Selenium interview questions and answers.
Frequently Asked Questions (FAQs)
What is TakesScreenshot in Selenium?
TakesScreenshot interface is used to capture the screenshots during the execution of the Selenium script. You can use the getScreenshotAs( ) method to capture a screenshot and store it in any specified location.
How do you use deprecated annotations?
You can use deprecated annotations by simply preceding the class, method, or member declaration with “@Deprecated.” The deprecated annotations are used to deprecate a class, method, or field.
Why is Selenium RC deprecated?
Selenium RC is deprecated due to its complex commands and unnecessary APIs. Moreover, it does not work with the HTMLUnit browser.
Citations
Co-Author: Saniya Gazala
Saniya Gazala is a Computer Science graduate from Reva University. She began as a manual tester, honing her skills in defect identification and problem-solving. Transitioning to technical writing, she simplified complex tech concepts for users. Her journey is marked by continuous learning and growth in the tech industry.
Got Questions? Drop them on LambdaTest Community. Visit now