Migrating to Selenium 4: Here’s What Has Changed

Image for post
Image for post

A guide to notable changes and deprecations for engineers looking to migrate from Selenium 3 to Selenium 4.

As of early September 2020, the alpha version of Selenium 4 is available and can be downloaded to explore.

Manoj Kumar has already explained at a high level what’s new in Selenium 4, and in this weekly blog series, we will discuss these features in detail with code snippets, benefits and possible use cases for the end users and well as the dev community who have built tools/products on top of Selenium.

Key takeaways

  • Understand the deprecated components and their replacements
  • Plan the migration from Selenium 3 to 4

Selenium is a toolset for web browser automation that allows us to remotely control browser instances and emulate a user’s interaction with the browser. There are many changes in Selenium 4, the major being the W3C standardization, which implies that Selenium can be integrated with any software without any compatibility issues. Along with W3C standardization, there are few new methods added and deprecated/replaced.

Let’s discuss these in detail.

What’s been deprecated in Selenium 4?

FindsBy

This is an internal change and does not impact end users, however if you have a product or tool built on top of Selenium APIs, have a look into these changes.

The By class can be used with findElement(By) and findElements(By) just like before.

Actions

A few new methods have been added to the Actions class as a replacement of the classes under package org.openqa.selenium.interactions:

click

clickAndHold

contextClick

doubleClick

release

Examples

These methods can be replaced as shown in the below code snippet as part of Selenium 4 implementation from line 37 to 53.

FluentWait

In the Selenium 3 example below, we see on line 6, the pollingEvery() method takes two parameters int and TimeUnit and can be imported from the package java.util.concurrent.TimeUnit. On line 7, withTimeout() also accepts int and TimeUnit as parameters.

Selenium 4 has replaced the TimeUnit with Duration and here is the sample code snippet demonstrating it. On line 12, pollingEvery() method now accepts only one parameter, Duration.

The Duration class can be imported from the java.time package and has methods to represent time duration in nano, millis, seconds, minutes, hours, days and so on.

In our example we have used ofMillis(int) and ofSeconds(int) methods.

Similarly, on line 14 withTimeout() method accepts Duration as a parameter.

Driver Constructors

This means you will need to create a specific Options object for whichever Driver class you’re using, set your requirements and pass this object to the Driver constructor.

Examples for each of the drivers can are below

ChromeDriver

Image for post
Image for post

ChromeDriver(Capabilities) is replaced by ChromeDriver(ChromeOptions).

SafariDriver

Image for post
Image for post

SafariDriver(Capabilities) is replaced by SafariDriver(SafariOptions).

EdgeDriver

Image for post
Image for post

EgdeDriver(Capabilities) is replaced by EdgeDriver(EdgeOptions).

FirefoxDriver

Image for post
Image for post

FirefoxDriver(Capabilities) is replaced by FirefoxDriver(FirefoxOptions).

InternetExplorerDriver

Image for post
Image for post

InternetExplorerDriver(Capabilities) is replaced by InternetExplorerDriver(InternetExplorerOptions).

Summary

The list of all deprecations can be explored in the Selenium WebDriver API docs. There are considerable internal interfaces, classes and ENUMs deprecated which have no impact on end users but may be of importance to vendors of tools and products built on top of Selenium.

In the next post of this series, we will explore the newly added features offered in Selenium 4 and the benefits they provide.

About the Author

Originally published at https://applitools.com on September 10, 2020.

Deliver visually perfect web and mobile apps with AI-powered end-to-end visual testing & monitoring. Get started, free: http://bit.ly/ApplitoolsFree

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store