×

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

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.

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.

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

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.

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

WebDriver-Tag Name Locator

Selenium WebDriver-Tag Name Locator The tag name locator is used along with the findElements() method to identify multiple similar elements in the UI. It is used to locate the web element with...

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

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 Tool Suite

The selenium tool suite is a combination of multiple software tools, and the entire tools having a different approach to support automation testing. Selenium test tool suites are as follows- Selenium...

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

Selenium Assertion

Selenium Assertion: In this section, we will learn about the Assertion in Selenium WebDriver. An Assertion is a feature available in TestNG, which is used to verify the expected result of...

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

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-CSS Selector: Substring Matching

CSS Selector: Substring Matching Selenium WebDriver In this tutorial, we will learn how to identify the web element using the substring method. A Sub-string contains three methods for identifying the web element...

9 minutes read.

Selenium WebDriver - Navigation Controls Commands

Navigation Controls Commands in Selenium WebDriver WebDriver is used to hold the browser history and perform browser navigation operations like, back, forward, and refresh. Whenever a WebDriver launches a browser, all...

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