How To Type, Retrieve and Clear values from the Text box and Text Area in Selenium WebDriver

A text box or an input box with free text is a very common web element on a web page. Generally, we type some values into a text box, retrieve typed value or delete typed values from it. A text box may also put some restrictions like a maximum length of allowed values, allowed characters or read-only, etc. There may be many more like highlighting text box for invalid values. In this post, we will focus on typing, retrieving, and deleting values from a text box.

What is a TextBox?

As per MDN – The HTML  element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety of types of input data and control widgets are available, depending on the device and user agent. The  element is one of the most powerful and complex in all of HTML due to the sheer number of combinations of input types and attributes. How an  works varies considerably depending on the value of its type attribute. If the type is “text” then it is an input box. If the type is “button” it is a button. For this post we will consider an input tag with type as text.

A sample text box in HTML

First name: 
Last name:

Save the above code in a file with extension as “.html”. Open the above HTML file in a browser. In fact methods used for performaing actions on a text box will work for text area as well.

What is a Text Area?

As per MDN – The HTML