Accessing Form and its Elements

September 25, 2016

In this tutorial, we will learn how to access different elements of a form using Selenium WebDriver. A form consists of various elements like text box, email field, password field, text area, radio buttons, checkbox, dropdowns, links, etc.

Let us learn how to interact with all these web elements and actions which can be performed

  • Input  Box – It consists of either a text field or an email field or a password field. The action which we can perform in a text box are:
  • Passing Text – method used is sendKeys(“String”);
  • Clearing Text – method used is clear();

facebooksignup

  • Radio Button – Radio button allows you to select one option out of many. The Action which can be performed on a radio button is click().
  • Checkbox – Checkbox allows multiple selections as well. A checkbox can be toggled ON/OFF by click() method.
  • Links – Links in html are hyperlinks, clicking on a link will navigate you to another page or document. Links are covered in detail in another tutorial Working with Link.
  • Dropdown – Dropdown is a web element which gives us many options to select from. Dropdown in HTML is represented by Select tag, and its elements are represented by option tag. Dropdown topic is covered in detail in another topic Working with Dropdown
  • Buttons – There are used to submit a form. Actions that can be performed on a button are click() and submit().
Practical Scenario: Sign-up form of Facebook

Scenario:

  1. Open any browser of your choice say chrome.
  2. Navigate to http://www.facebook.com
  3. Fill up the sign-up form on the home page. This sign-up form consists of web elements like email field, password field, dropdown, radio button and buttons.

facebooksignup

Refer the below code:

This was the basic introduction to form elements, going forward we will learn all these elements in detail with many practical scenarios.

For any questions, queries or comments feel free to write us at support@qatechhub.com or saurabh@qatechub.com. Happy Learning 🙂

Saurabh

About the Author

Saurabh

Follow Saurabh:

Leave a Comment: