software testing

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 the first to come into the market in 2004 as a 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 the programming language, It supports rapid test development. Selenium is just a record-and-play tool.

Selenium WebDriver: It automates the browser and supports different programming languages like Java, JavaScript, Perl, Python, etc.

Selenium Grid: Selenium Grid 4 allows us to run the test script across different machines or systems.

automation testing service provider

Features of Selenium 4

There is a different new feature provided by selenium 4, the feature is as follows:

1) Capture screenshots of specific web elements: 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 file=logo.getScreenshotAs(OutputType.FILE);

File destFile =new File(“logo.png”);

FileUtils.copyFile(file,destfile);

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 URLs in two different tabs at the same time, this can be possible using Selenium 4, please check the below code:

driver.get(“https://www.google.com”);

driver.swithTo().newWindow(WindowType.TAB);

driver.navigate().to(“https://facebook.com”);

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 the user wants to access two different applications on the same browser the user can now do this by:

driver.get(“https://www.google.com”);

driver.swithTo().newWindow(WindowType.Window);

Driver.navigate().to(“https://facebook.com”);

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 a 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 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 the 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 to 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

Conclusion:

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.

Read Also:

Benefits of Selenium Webdriver for Automation Testing

Related Post

QACraft-white logo

© Copyright 2024 QACraft Pvt. Ltd. All rights reserved.

Contact : +91 9157786796