Back to Resources

Blog

Posted October 12, 2021

Selenium 4 Knowledge Hub is now live

Selenium 4 started its development in late 2018, had its first Alpha release in April 2019, and moved to Beta in February 2021. It was released October 13, 2021. Learn what you need to know about this release from the Selenium 4 Knowledge Hub by Sauce Labs.

quote

Overview

Several new features and benefits for automated testing are included in the upcoming Selenium 4 release, such as:

  • Relative locators

  • Better window and tabs managing

  • Improved Selenium Grid

  • Use of W3C by default under the hood

  • A set of bidirectional APIs designed for intercepting network requests, authentication on secure pages, listening to DOM events and more. These are currently implemented through the Chrome DevTools Protocol (CDP), but in the future WebDriver BiDi will be used.

Selenium 4 has been designed to be a drop-in replacement, but there might be cases where tests or dependencies need to be adjusted. We recommend you to go through the following sections to understand better how this new version will benefit you and what potential changes might be needed to upgrade.

Sauce Labs has contributed to the development of Selenium 4, and thanks to that, you can rest assured that your tests will continue to work on our platform.

How to Upgrade to Selenium 4

The Selenium team has spent a good amount of time making the upgrade process as painless as possible. A few things have been deprecated, so you might hit a couple of issues while upgrading, especially if you have built custom functionalities in your testing framework. This guide will show you how to move from Selenium 3 to Selenium 4.

New Features in Selenium 4

Relative Locators

A new way of locating elements by using more natural language friendly terms, such as “above”, “below”, “left of”, “right of”, and “near”. In general, you could think about them as a way to locate elements based on the visual placement on the page. Check how to use the new Relative Locators here.

New Window & Tab utilities

Selenium 4 includes a new command to help users create a new tab or a new window. Check some code examples that show how to use it.

Print Page as PDF

Selenium 4 will allow users to print a page as a PDF through Chrome and Firefox. Examples with each browser can be seen here.

New features with Firefox

The upcoming version of Selenium exposes a few new features with Firefox, such as a full page screenshot, a simplified way to install add-ons, and updating Firefox preferences in the middle of the session. Check them here.

Setting network conditions with Chrome and Edge

Selenium 4 exposes a set of utilities to modify the network conditions in Chromium based browsers, useful to test web applications under different network conditions. Check the details here.

New Element Attribute and Property methods

Two new methods have been added to more precisely get a given element attribute or a property. It is recommended to use one of the new methods for performance and preciseness, specially if you are using Sauce Labs. Read more about them here.

New Selenium Grid

Selenium Grid 4 has been rewritten from scratch, with all the learnings from the past. It takes advantage of modern infrastructure (such as Docker and distributed tracing). Read more details about it here.

Bidirectional APIs

Selenium 4 offers new functionality useful for both browser automation and testing, specifically with a set of bidirectional APIS. Through it, you will get more information from the browser and more control over the application under test. While the WebDriver BiDirectional Protocol is getting implemented across all browser vendors, these features will be offered through the Chrome DevTools Protocol (CDP). Check some examples that show how to use it here.

Frequently Asked Questions

Check a list of the most commonly asked questions about the upcoming Selenium version here.

Titus Fortner
Sr. Developer Experience Engineer, Sauce Labs
Diego Molina
Staff Software Engineer at Sauce Labs
Published:
Oct 12, 2021
Topics
Share this post
Copy Share Link
© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.