Selenium 4 – New Features And Improvements

This Review Lists the Differences Between Selenium 3 vs  Selenium 4 and New Features & Changes in the Latest Version Selenium 4 (Alpha 3):

Selenium 4 (Alpha 3) version is now launched in the market. As we all know the founder of Selenium is “Simon Stewart” and now he has introduced the new version not only for web drivers but also for Grid and IDE.

Selenium 4 adopted the W3C standard Web Driver Protocol. All the browsers like Google Chrome, Safari, Internet Explorer, Edge, and many more also follow the W3C standard due to which interaction between browser driver and Selenium Web Driver will now be based on W3C standard web driver protocol.

New features in Selenium 4

Selenium 4 Review

The changes related to W3C standards are made to improve the version, as earlier Selenium commands worked very differently on different browsers.

Note: Selenium 4 Alpha version released in April 2019.

Download the Selenium 4 Alpha version by clicking on “4.0.0-alpha-6” as shown in the image below:

Selenium 4 Alpha version

The latest version Libraries are present on Maven Central Repository.

Recommended Reading=> Selenium Remote Driver

selenium remote driver

Difference Between Selenium 3 And Selenium 4

Selenium 3Selenium 4
The Browser interaction is based on JSON wire protocol due to which it needs encoding and decoding of the API It follows the W3C standard Protocol due to which driver and the browser communication follows the standard procedure, does not require encoding and decoding of the API, so communication happens directly.

Important Architecture Related Changes

#1) Supports removed for some browsers: Now, they have removed the supports for the browsers Opera and Phantom JS. Opera users can use the Chrome browser, whereas Phantom JS users can use Chrome or Firefox in headless mode.

#2) Optimized Selenium Grid: Selenium Grid was developed long back in 2011.

Selenium 4 has come up with new architecture to remove the issues which occurred earlier during installation and configuration, also during the connection between the hub and node machine.

Let’s understand in brief about the Selenium Grid, which contains two major components:

  • Node: It is used to execute tests on individual computer systems. There can be multiple nodes in a grid.
  • Hub: It is the central point from where it controls all the machines present in the network, and it contains only one hub which helps in allocating test execution to different nodes.

But in Selenium 4, Grid is very flexible. It allows us to test the cases against multiple browsers, browsers of different versions, and also on different Operating systems. Even now, there is no need for a setup to start hub and nodes individually once the user starts the server, the Grid automatically works as both nodes and hub.

It also supports advanced tools like Docker, AWS, Azure, and much more, useful in the DevOps process. Now Grid has a more user-friendly UI and contains relevant information related to the session, running, capacity, etc.

>> Click here for more information.

#3) Standardized Documentation: Documents play an essential role for any user, and Selenium documents were not updated since Selenium 2.0.

With Selenium 4, they have updated all the official documents related to Selenium that include web driver, Grid, and IDE to explain the latest changes.

#4) Improvement in Selenium 4 IDE: Selenium IDE is a record and playback tool that is used for user interaction with the browser, and the new version of IDE is available with more features

These features include:

  • It improves the browser support. Now with a new version, any browser vendor can easily plug into the latest Selenium IDE.
  • CLI Runner will be based on NodeJS, not the HTML-based runner, and it supports the parallel execution from which it provides the report with the total number of test cases passed/failed along with execution time taken.

#5) Better Monitoring: Logging and request tracing process are now improved to make a better grip on the debugging process for automation engineers as it is not limited to DevOps only.

Features Of Selenium 4

The features are as follows:

#1) Capture screenshot of specific web element:

Earlier, users can take a screenshot of the entire page as there was no provision to take the screenshot of the specific web element. But with Selenium 4, users can take the screenshot of a specific web element.

Please find the below code:

WebElement logo=driver.Findelement (By.xpath(“//div[@id=’divLogo’]//img”));
File file=logo.getScreenshotAs(OutputType.FILE);
File destFile =new File(“logo.png”);

#2) Open the new tab on the browser:

Now, in Selenium 4, the user can open a URL in a new tab along with the existing tab.

For Example: If the user wants to open 2 URLs in two different tabs at the same time, the user can do that with the Selenium 4.

Please find the below code for reference:


#3) Open a new window on the browser:

Using Selenium 4, the users can also open the new window on the same browser.

For Example, if the user wants to access two applications in the same browser, the user can now do this.

Please find the below code for reference:


#4) Object Location:

Now with Selenium 4, users can achieve the coordinates, dimension, height, width, etc. as the location of the web elements or object.

Please find the below code for your reference:

WebElement logo1=driver.Findelement(By.xpath(“//div[@id=’divLogo’]//img”));
System.out.println(“Height:” +logo.getRect().getDimension().getHeight());
System.out.println(“Height:” +logo.getRect().getDimension().getWidth());
System.out.println(“X Location: “ +Logo.getRect().getX());
System.out.println(“Y Location: “ +Logo.getRect().getY());

#5) Relative Locators:

These are also known as Friendly Locators, and this functionality is being added to find out the element which is present nearby to other web element or, we can say that it can find the web elements based on GUI location.

There are five locators added in Selenium 4:

  • below(): Web element located below for the specified element.
  • toLeftOf() : Target web element which is present to the left of specified element.
  • toRightOf(): Target web element which is presented to the right of a specified element.
  • above(): Web element located above for the specified element.
  • near() : Target web element which is away(approx. 50 pixels) from the specified element.

Note: All the above relative locators method support “withTagName” method.

The below example is for the toLeftof() and below() locators:

WebElement book;
book = driver.Findelement(RelativeLocators.withTagName(“li”).toLeftOf(“pid1”))
String id1=book.getAttribute (“id1”);

The below example is for the toRightOf() and above() locators:

WebElement book1;
book1 = driver.Findelement(RelativeLocators.withTagName(“li”).toRightOf(“pid1”))
String id2=book1.getAttribute (“id2”);

#6) Chrome Dev tools:

In the new version of Selenium, they have made some internal changes in the API. Earlier in Selenium 3, the Chrome driver extends directly to the Remote Web Driver class. But now in Selenium 4, Chrome driver class extends to Chromium Driver. Chromium Driver class has some predefined methods to access the dev tool.

Note: Chromium Driver extends the Remote Web driver class.

By using the API, we can perform the following operations:

  • Enable Network Offline
  • Enable Network Online
  • Get Console Logs
  • Load Insure Web Site


In this tutorial, we have covered the introduction to the new version of Selenium 4, some upcoming features related to Selenium Grid, IDE, and Selenium WebDriver.

We have also seen a brief description of the Relative Locators, Chrome dev tools. We can expect a lot from the Selenium 4, be it the browser support, the documentation, or the UI.

Author: This article is written by Akanksha K who has 7+ years of experience in Software Quality and building Test Frameworks.