Introduction: Selenium 4 features
Selenium is one of the widely used automation testing tools in the market which is used to test web applications. Selenium is first to come into the market in 2004 as selenium core. After it has some extended version.
Table of Contents
What is new in selenium 4?
To use selenium 4 there is no need of having extensive knowledge of programming language, It supports rapid test development. Selenium is just a record and play tool.
Selenium Grid: Selenium Grid 4 allows us to run the test script across different machines or systems.
Features of Selenium 4
There is a different new feature provided by selenium 4, the feature is as follows:
1) Capture screenshot of specific web element: Earlier in selenium 3 users can capture screenshots of the whole page but Selenium 4 comes with a new feature where users can capture screenshots of a specific web element.
Please find the below code:
WebElement logo=driver.Findelement (By.xpath(“path of webelement”))
File destFile =new File(“logo.png”);
2) Open the new tab in the browser: In selenium 4 we can open a new tab in the browser along with the existing tab.
For Example: If a user wants to open two URL in two different tabs at the same time, so this can be possible using selenium 4, please check the below code:
3) Open a new window in a new browser: In selenium 4 user can open a new window on the same browser.
For example: suppose if the user wants to access two different applications on the same browser the user can now do this by:
4) Object Location: now using selenium 4 users can achieve the exact location of web elements like the coordinates, dimension, height, width, etc as the location of the object.
Please find the below code for reference:
WebElement element=driver.findelemet(By.xpath(“path of the element”));
System.out.println(“height is :”+element.getRect().getDimension().getHeight);
System.out.println(“width is :”+element.getRect().getDimension().getWidth);
System.out.println(“X location :”+element.getRect().getX());
System.out.println(“Y location :”+element.getRect().getY());
5) Relative Locators: Relative locator is also known as a friendly locator and this functionality is added to find out the element on a page nearby the other element, we can say that a relative locator is used to find Web element on a web page.
There are five locators used in selenium 4 please check below:
- below (): below () is used to find the element below to the specific web element.
- toLeftOf(): It finds the web element which is left to the specified element.
- toRightOf(): It finds the web element which is right to the specified web element.
- above (): It finds the element which is above the specified element.
- near (): near () target an element that is away from (approx. 50 pixels) from a specified web element.
Please check the below example to check how to use toLeftOf() and below() locator:
WebElement element =driver.findelement(RelativeLocators.withTagName(“li”).toLeftOf(By.id(“pid1”))).below(By.id(“pid2”));
String id1= element.getAttribute(“id1”);
Also please check below example to check the use of toRightOf() and above() locator:
WebElement element =driver.findelement(RelativeLocators.withTagName(“li”).toRightOf(By.id(“pid1”))). above(By.id(“pid2”));
String id1= element.getAttribute(“id1”);
6) Chrome Dev Tool: In selenium 4 they have made some internal changes on API. In selenium 3 the chrome driver extends directly to the remote driver class but selenium 4 comes up with certain changes in this, in selenium 4 chrome driver class extends to Chromium Driver. The chromium driver class in Selenium 4 includes various predefined methods for accessing the development tool.
By using API, we can perform the below operation:
- It enables network offline
- Enable Network Online
- Get console log
- Load insures web site
In this tutorial, we have covered the Introduction, what is new, what new feature is provided by selenium 4, what is the relative locator, and how we can use this locator. we can expect a lot of new things from selenium 4 and it gives us the best experience and ability to do all the tasks.