×

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

Selenium WebDriver-CSS Selector locator

Selenium WebDriver-CSS Selector locator A CSS selector is used to identify the web element based on their “# id” and “. Class”, Html tags, and attributes. A CSS stands for Cascading Style...

1 minute read.

Selenium-IDE Locators

Selenium-IDE Locators: Before we start learning about Selenium –IDE Locators, firstly we have to learn about UI elements. UI Elements -UI elements are the elements which are displayed on the web application....

1 minute read.

Operational Controls Methods in Selenium WebDriver

Operational Controls Methods The Operational controls are used to perform all the actions on the web elements like click on the button, pass the value in the text box, and click...

4 minutes read.

Selenium Testing

Selenium is a functional testing tool and compatible with non–functional testing tool. Selenium is free and not required any licensing. There are specified types of testing that can be automated using Selenium:-   Functional Testing: Checking every component...

3 minutes read.

Difference between Selenium WebDriver and Selenium RC

Difference between Selenium WebDriver, and Selenium RC: Selenium WebDriver and selenium RC (Remote Control) both are different in any manners which we see later in this tutorial, let us see the...

3 minutes read.

Selenium WebDriver - IE [Internet Explorer] browser

Selenium WebDriver - IE [Internet Explorer] browser In this segment, we will understand how to run a test script with the help of the IE (Internet Explorer) browser. It is a standalone...

4 minutes read.

Selenium WebDriver-CSS Selector: Tag and ID

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

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.

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- 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.

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.

Drawback or Limitations of Selenium

Drawback or Limitations of Selenium Followings are the Drawback or limitations of Selenium:- Drawback /LimitationsDescriptionDesktop applications cannot be automated by Selenium.To test the desktop application, we have tools like Test Complete, Winnium, and...

2 minutes read.

CSS Selector Locator in Selenium IDE

It used to identify the web element based on HTML tag, id, class, and attributes. To describe the look and formatting of a document written in the markup language are known...

1 minute 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.

WebDriver-Id Locator

WebDriver-Id Locator: The Id Locator is used to identify any web element in UI with the help of the ID attribute. The First preference is always goes to ID locator while inspecting...

4 minutes read.

Selenium-IDE Login test

Login test for Selenium-IDE Now we are learning, how to create a Login/sign-up Test case in Selenium IDE. For our testing purpose, we are going to test the login page provided by...

2 minutes read.

CSS Selector: Attribute in Selenium IDE

CSS Selector: Attribute Locating the attribute of a CSS selector, we would access the Password textbox, which is present in the login form of Facebook. The Password textbox has a type attribute...

1 minute 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.

Selenium WebDriver - Google Chrome Browser

Selenium WebDriver - Google Chrome Browser In this tutorial, we will learn how to run our Selenium Test Scripts in the Google Chrome Browser. To implement the WebDriver protocol with the help...

3 minutes read.

Selenium WebDriver-Locators

Selenium WebDriver-Locators The WebDriver uses the same set of locating strategies like selenium -IDE for specifying the location of the web element. Each locating strategy has its command in Java to locate...

1 minute read.