DEV Community

Cover image for What's new in Selenium 4?
Manoj Kumar
Manoj Kumar

Posted on


What's new in Selenium 4?

A cross-post of Selenium 4 article.

A lot of developments have happened since Selenium 4 was announced during the State of the Union Keynote by Simon Stewart and Manoj Kumar. There has been a significant amount of work done and we’ve released at least six alpha versions of Selenium 4 for users to try out and report back with any potential bugs so that we can make it right.

Selenium WebDriver

One of the main reasons to release WebDriver as a major version (Selenium 4) is because of the complete W3C protocol adoption. The W3C protocol dialect has been available since the 3.8 version of Selenium WebDriver along with the JSON wire protocol. This change in protocol isn’t going to impact the users in any way, as all major browser drivers (such as geckodriver and chromedriver), and many third party projects, have already fully adopted the W3C protocol.

However, there are some notable new APIs, as well as the removal of deprecated APIs in the WebDriver API, such as:

  • Elements:
    • The FindsBy* interfaces (e.g. FindsByID, FindsByCss …) have been deleted. The recommended alternative is to use a By instance passed to findElements instead.
    • “Relative locators”: a friendly way of locating elements using terms that users use, like “near”, “left of”, “right of”, “above” and “below”. This was inspired by an automation tool called Sahi by Narayan Raman, and the approach has also been adopted by tools like Taiko by ThoughtWorks.
    • A richer set of exceptions, providing better information about why a test might have failed. These include exceptions like ElementClickInterceptedError, NoSuchCookieError & more.
  • Chrome Debugging Protocol (CDP): Although Selenium works on every browser, for those browsers that support it, Selenium 4 offers CDP integration, which allows us to take advantage of the enhanced visibility into the browser that a debugging protocol gives. Because the CDP is, as the name suggests, designed for debuggers, it’s not the most user friendly of APIs. Fortunately, the Selenium team is working to provide comfortable cross-language APIs to cover common requirements, such as network stubbing, capturing logs, mocking geolocation, and more.
  • Browser Specifics: A new ChromiumDriver extends packages for both Chrome and Edge browsers. A new method to allow install and uninstall add-ons for Firefox browser at runtime.
  • Window Handling: Users can go in full-screen mode during script executions. Better control of whether new windows open as tabs, or in their own window.
  • Screenshots: An option to grab a screenshot at UI element level. Unlike the usual view-port level screenshot. Full Page Screenshot support for Firefox browser.

What’s next in WebDriver beyond Selenium 4?

It would be nice to have users extend the locator strategy like FindByImage or FindbyAI (like in Appium) – right now we have a hardcoded list of element location strategies. Providing a lightweight way of extending this set, particularly when using Selenium Grid, is on the roadmap.

There are a lot of other features added to Selenium IDE and Selenium Grid. Please refer for more content

Top comments (0)

50 CLI Tools You Can't Live Without

The top 50 must-have CLI tools, including some scripts to help you automate the installation and updating of these tools on various systems/distros.