Frequently Asked Questions About Selenium 4

Posted Oct 29th, 2021

What are the main benefits of using Selenium 4?

Standards based protocol

Selenium 4 uses the W3C WebDriver standard protocol for browser automation. As browser vendors will only support W3C WebDriver in the future, using Selenium 4 ensures the widest possible range of support across all browsers, making your automation scripts future proof.

Relative locators

A new way of locating elements by using more natural language friendly terms, which simplify the process of locating elements. In general, you could think about them as a way to locate elements based on the visual placement on the page. The following locators have been added:

  • below - web element located below the specified element

  • toLeftOf - web element located to the left of the specified element

  • toRightOf - web element located to the right of the specified element

  • above - web element located above the specified element

  • near - web element located near (approx. 50 pixels) the specified element

New window & tab command

You can now open a new window or a new tab along an existing tab . It was common to see automation scripts sending a combination of keys such as “Ctrl” + “T” to open a new tab, but now this can be achieved through native commands.

New browser features exposed

Selenium 4 allows you to use a set of new features available in different browsers. A few of these features are:

  • Printing pages as PDF with Chrome and Firefox.

  • Installing/uninstalling add-ons, full page screenshots, and changing browser preferences mid session with Firefox.

  • Modifying network conditions with Chromium based browsers.

A set of bidirectional APIs

The new version of Selenium offers new functionality useful for both browser automation generally 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). With the new methods you can:

  • View console logs

  • Intercept network requests and mock backends

  • Perform Basic Authentication to circumvent browsers that have disabled it

  • Execute bootstrap scripts to improve test execution time

  • Throttle network performance to simulate real world conditions

Does Sauce Labs support all the new features of Selenium 4?

At launch, Sauce Labs will support all features except for the Bidirectional APIs (implemented through CDP). While we are working hard to add full support we do provide similar functionality through our Extended Debugging feature. Using Extended Debugging you can:

  • Intercept network requests to mock backends

  • Throttling performance of both network and CPU

  • Access console and network logs

Do I have to change my tests?

If you've already updated your Selenium 3 capabilities to be W3C compliant, your code should continue to work. Some of the language bindings have updated the recommended code for 4.0, however, so some minor changes might be desired. More details can be found in our upgrade guide.

Will my tests still run on the Sauce Labs platform?

Tests will continue to run on our platform. However, if you are not doing it yet, Sauce Labs specific capabilities need to be placed inside the sauce:options block. With that, Sauce specific features for your tests (specifying browser versions, initiating secure tunnels, Extended Debugging, etc.), will continue to work well.

Examples showing how to create a sauce:options block can be seen in our upgrade guide and in the Selenium section inside the Sauce Labs docs.

Sauce Labs is here to help

We encourage you to upgrade your tests to Selenium 4 and run them on our platform. Our upgrade guide and Selenium documentation are available for your reference during the upgrade process. Go through them and let us know what you think by getting in contact with us.

Want to Learn More?

Written by

Mike Donovan