×

Verification Controls Methods in Selenium WebDriver

Verification Controls Methods

 The verification controls methods are used to check whether the web element is displayed, enabled, and selected.

Verification Controls Methods

Some of the most commonly used verification controls are as follow:

Verification controls Description Return Type Command Syntax
isDisplayed() It is a method, and it is used to check whether the element is available in GUI. It return Boolean true value if the object is available. isDisplayed() : boolean   element.isDisplayed();    
isEnabled() It is used to check whether the element/object is active or performable or not It returns true value, if the object is enabled. isEnabled() : boolean   element.isEnabled();    
IsSelected() It is used to check whether the checkbox or radio button is already selected or not. It returns true, if element is selected already. isSelected() : boolean   element.isSelected();    

Let us take a sample test script in which we will try to cover mostly used verification_controls Commands:

For our testing purpose, we are using the login page of yahoo to perform mainly used data capture commands of web element controls.

In this test, we will automate the following test scenarios:

Steps Action Method Used Input Excepted Result
1. Open the Chrome Browser System.setProperty()   The Chrome browser must be opened.
2. Navigate to the yahoo login page. get() www.yahoo.com The login page must be displayed.
3. Identify the logo image, which is above an email edit box. And verify the logo image.   isDisplayed()   The logo image should be displayed.
4. Verify that the stay sign-in box is selected or not isSelected()   Stay sign-in box should be selected by default.  
5. Verify that the Button is enabled or not.   isEnabled()     The button should be enabled.  
6. Close the browser close()   The browser should be closed.

Open the Eclipse IDE and the existing test suite new_test, which we have created in WebDriver Installation section of WebDriver tutorial.

Then, right-click on the folder called src and create a new Class File from New → Class.

click on the folder called src and create a new Class File
  • And give the Class name as verification_controls and click onthe Finish button.
Class name as verification_controls

We are creating our test case step by step to give you a complete understanding of verification _controls Commands in WebDriver.

Step1:

To launch the Google Chrome browser, we need to download the ChromeDriver.exe file and set the system property to the path of ChromeDriver.exe file.

Hence, here is the code for setting the system property for the google chrome:

//set the system property of Google Chrome
System.setProperty("webdriver.chrome.driver","C:\Users\JTP\Downloads\chromedriver_win32\chromedriver.exe");  

To initialize the Chrome driver using ChromeDriver class:

// create driver object for CHROME browser
WebDriver driver=new ChromeDriver(); 

Step2:

Launch the desired website using get() method.

//navigate to yahoo login page
driver.get("https://login.yahoo.com"); 

Step3:

Identify the logo image, which is above an email edit box, and verify the logo image using isdisplayed() verification method.

//identify the logo image, which is above the email edit box
WebElement iwb=driver.findElement(By.xpath("(//img[@class='logo'])[2]"));
//image should be display
boolean status=iwb.isDisplayed();
System.out.println("image status is => "+status); 

Step4:

  • Verify that the stay sign-in box is selected or not using isSelected() verification method.
// stay sign-in box should be selected by default
WebElement iwb1=driver.findElement(By.id("persistent"));
boolean status1 =iwb1.isSelected();
System.out.println("check box is selected =>" +status1);

Step5:

Verify that the Button is enabled or not using isenabled() verification control method.

//element should be enabled
WebElement iwb2=driver.findElement(By.xpath("//input[@id='login-signin']"));
boolean status2=iwb2.isEnabled();
System.out.println("button is enabled =>" +status2); 

Step6:                                                                                 

Finally, we terminate the process and close the browser.

 //Close the browser 
driver.close();  

The our final test script will look like this

package testpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class verification_controls {
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\Users\JTP\Downloads\chromedriver_win32\chromedriver.exe");
// create driver object for CHROME browser
WebDriver driver=new ChromeDriver();
//navigate to yahoo login page
driver.get("https://login.yahoo.com");
//identify the logo image which is above the email edit box
WebElement iwb=driver.findElement(By.xpath("(//img[@class='logo'])[2]"));
//image should be display
boolean status=iwb.isDisplayed();
System.out.println("image status is => "+status);
// stay sign in box should be selected by default
WebElement iwb1=driver.findElement(By.id("persistent"));
boolean status1 =iwb1.isSelected();
System.out.println("check box is selected =>" +status1);
//element should be enabled
WebElement iwb2=driver.findElement(By.xpath("//input[@id='login-signin']"));
boolean status2=iwb2.isEnabled();
System.out.println("button is enabled =>" +status2);
//close the driver
driver.close();
}
} 
  • To run the test script in Eclipse, right-click on the window and then click Run as → Java application.
To run the test script in Eclipse
  • The test script will be launched in the chrome browser and automate all the test scenarios.
  • And the output console window will show the results for all the print commands.
test script will be launched in the chrome browser

 

 


Related Topics

First test case of Selenium-IDE

First Test Case of Selenium-IDE: In this part, we are discussing how to create a basic test case in Selenium-IDE: The entire test script execution process in Selenium -IDE can be divided...

4 minutes read.

Selenium WebDriver Characteristics

Characteristics of Selenium WebDriver Some of the essential characteristics of Selenium WebDriver are as follows: Multiple Operating System Support Selenium Webdriver supports multiple operating systems like: Desktop OS: Window, Linux, and macOS Mobile OS:...

2 minutes read.

Advantages and Disadvantages of Selenium-IDE

Advantages and Disadvantages of Selenium-IDE Advantages of Selenium IDE: UI based record and playback tool. Easy to understand & developed a test script. Selenium-IDE test script export into web driver code & Selenium–RC It is...

1 minute read.

Selenium-IDE Installation in Chrome

Selenium-IDE Installation Since Selenium IDE is designed only for Firefox and Chrome plug-in, we are assuming that you have already installed the Google Chrome browser in your system. However, you can...

1 minute read.

Selenium WebDriver-CSS Selector: Tag Class and Attribute

Selenium WebDriver-CSS Selector: Tag, Class, and Attribute We will locate the web element with the help of Tag, class, and attribute CSS selector locator in this section of the tutorial. Where Tag,...

5 minutes read.

Selenium WebDriver- Checkbox handling

Selenium WebDriver- Checkbox handling In this tutorial, we will be learning about handling the checkbox in selenium WebDriver. Let us take one example to give you a better understanding of Checkbox handling,...

4 minutes read.

Selenium WebDriver Tutorial

Seleniun WebDriver Introduction Selenium WebDriver is the essential tool of Selenium Tool Suite because it can directly communicate the browser without any server.  Selenium WebDriver is a browser automation framework that accepts...

3 minutes read.

Selenium WebDriver - Firefox or Gecko (Marionette) browser

Selenium web driver-Firefox or Gecko (Marionette) browser In this tutorial, we are going to learn how to run the Selenium WebDriver test script in the Firefox Browser using the Gecko Driver. Before going...

4 minutes read.

Id Locator in Selenium IDE

Id Locator Id locator is used to find the web element by the help of id of that element because ID is likely to be unique for each web element. Target Format: Id=id of the...

2 minutes read.

Verification Controls Methods in Selenium WebDriver

Verification Controls Methods  The verification controls methods are used to check whether the web element is displayed, enabled, and selected. Some of the most commonly used verification controls are as follow: Verification controls Description Return...

4 minutes read.

CSS Selector: ID in Selenium IDE

CSS Selector: ID The id attribute is used to identify the web element uniquely in the web pages. Syntax of ID Attribute:  [HTML tag][#][Value of ID attribute] The hash sign (#): it is mandatory while using the...

1 minute read.

WebDriver Interface | Class Diagram

WebDriver interface/class diagram: The interface of WebDriver includes the following stages, which is as follows: Search Context Web driver Remote web driver Driver class Search Context  The first interface of the web driver class is search Context,...

2 minutes read.

Selenium WebDriver-CSS Selector: Tag and Class

Selenium WebDriver-CSS Selector: Tag and Class We will locate the web element with the help of tag and class CSS selector in this section of the tutorials Where Tag and class are...

4 minutes read.

Characteristics of Selenium IDE

Characteristics of Selenium IDE Selenium IDE is separated into different parts, each having their features and functionalities. The seven various components of Selenium IDE are as follows: MENU BAR: The menu bar is...

3 minutes read.

Selenium WebDriver-CSS Selector: Tag and Attribute

Selenium WebDriver-CSS Selector: Tag and Attribute We will locate the web element with the help of Tag and attribute CSS selector in this section of the tutorial. Where Tag and attribute are...

5 minutes read.

CSS Selector: Class in selenium IDE

CSS Selector: Class Identify a web element with the help of Class as a CSS Selector is like using id attribute. The only difference between Class and id is in their...

2 minutes read.

Selenium WebDriver- Microsoft Edge Browser

Selenium WebDriver- Microsoft Edge Browser: In this tutorial, we will learn how to launch the Microsoft Edge browser in the Selenium WebDriver. Before we start automating our test script with Microsoft Edge...

4 minutes read.

WebDriver-Class Name Locator

WebDriver-Class Name Locator In this tutorial, we will learn about the Class name locator of selenium WebDriver. The Class Name locator is used to identify any element in UI based on the...

4 minutes read.

Mouse and Keyboard Controls in Selenium WebDriver

Mouse and Keyboard Controls in Selenium WebDriver In this tutorial, we will learn about how to handle mouse and keyboard event using action class in selenium WebDriver. Action Class in Selenium WebDriver: Action...

13 minutes read.

Selenium vs QTP

In this section, we are comparing the most frequently used automation tool –Selenium and QTP. Selenium and QTP have relative advantages over each other- FeaturesSeleniumHP QTPLicensingSelenium is an open-source testing tool....

3 minutes read.