Select Page
Selenium Testing

Selenium TextBox Actions & Validations

In this blog article, you will learn all Selenium's action and validation snippets for TextBox.

Selenium TextBox Actions & Validations
Listen to this blog

In Selenium, every HTML object is considered as WebElement. As an automation tester, you should be aware of what are all the applicable actions and validations for each HTML objects. In this blog article, you will learn all Selenium’s action and validation snippets for TextBox. As per W3C, a mutable HTML textbox should allow the user to edit value and it should not allow Line Feed & Carriage return characters.

Let’s start from some basics commands.

Enter Value

ChromeDriver driver = new ChromeDriver();
WebElement txtBox = driver.findElement("txt2"));

//Entering using SendKeys

//Entering using JavaScript

Please note that the JavaScript snippet does not mimic user action the way how SendKeys does.

IsEnabled & ReadOnly

Before checking whether a textbox is enabled or readonly, you should know what is the difference between disabled and readonly textbox.

Readonly – If a textbox is readonly, you can still send the textbox’s content when a form is submitted and access the textbox using TAB key.

Disabled – If a textbox is disabled, the textbox’s content will not be sent when a form is submitted, you can’t access the textbox using TAB key, and the events like click, hover, & double click will not be triggered.

isReadOnly = txtBox.getAttribute("readonly");

isEnabled = txtBox.isEnabled();

Retrieve Value

Retrieving value from a textbox using Selenium is a cake walk for many. However, we, as an automation test company, would like to list it here. So that this blog article will be a quick reference guide for software testers who are learning Selenium.

value = txtBox.getAttribute("value");


Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us