×

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 WebDriver-XPath Locator

Selenium WebDriver-XPath Locator The locators can make the object identification of all the selenium tools. There are eight locators available in selenium web driver, but most of the time we go for...

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

Selenium WebDriver-Alert Popup

Selenium WebDriver-Alert Popup  An alert popup is one of the small message boxes, which used to give some information to the user that displays on the browser. The Alert popup will be...

6 minutes read.

WebDriver-Link Text locator

WebDriver-Link Text locator The Link text locator is used to identify only web link elements based on the value of the link. The Link text locators cannot be used for other than...

4 minutes read.

Selenium WebDriver – Window handling

Selenium WebDriver – Window handling In this tutorial, we will understand how we can handle the window, multiple windows, and pop-ups in selenium WebDriver. We have different types of window, and pop-ups...

7 minutes read.

Xpath locator in Selenium IDE

X PATH LOCATOR: Xpath is used to identify the element using any attribute or visible test. Syntax for X PATH:- //html tag [@attribute=’value’] e.g. - //div [@class=’label’]                    OR //html tag [text () =’Visible Text’] e.g.-//div [text...

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

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-IDE Installation in Mozilla Firefox

A beginners guides to Selenium-IDE Installation Since Selenium IDE is designed only for Firefox and Chrome plug-in, we are assuming that you have already installed the Mozilla Firefox browser in your...

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.

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 WebDriver installation

Installation Steps of Selenium WebDriver In this tutorial, we will see the process of selenium webdriver installation. Selenium WebDriver installation process is done in four Stages: Java Installation (version 8 or higher version) Eclipse...

4 minutes read.

Selenium WebDriver- Radio button handling

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

3 minutes read.

Name Locator in Selenium IDE

NAME LOCATOR: It is used to find the name in the web element. If we have multiple web elements of the same name, then the first matched element would be returned. Open the...

3 minutes read.

Data-Capture Controls Methods in Selenium WebDriver

Data-Capture Controls Methods: The data-capture controls are used to determine the text, size, location, and the CSS value of the web element, etc. Some of the most commonly used data-capture controls are...

7 minutes read.

CSS Selector: ID/Class and Attribute in Selenium IDE

CSS SELECTOR: ID/Class and Attribute The Id, class, and attribute of CSS selector are used to identify the web element to access the web pages.  Syntax for Id/Class and Attribute: css= <./#> {[attribute=Value of...

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

Selenium Tutorial

What is Selenium? Selenium is a functional testing tool and compatible with the non-functional testing tools also. Selenium is free and does not require any licensing. Functional tests script executed by...

6 minutes read.