Automating textboxes, text areas, and buttons
The textbox and button elements are the most common elements used in any web application. Selenium WebDriver's WebElement interface provides methods to simulate keyboard entry into textboxes or text areas and perform clicks on a button control.
In this recipe, we will explore these methods to automate textbox, text-area, and button elements.
How to do it...
Here we will explore the clear()
, sendKeys()
, submit()
and click()
methods of the WebElement
interface.
Clearing text from textbox and text-area elements
To clear the existing text value from textbox and text-area elements, we can use the clear()
method, as shown in following code example:
// Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Clear the existing text value using clear method element.clear();
Entering text in textbox and text-area elements
To enter text value in a textbox or a text-area element, we can use the sendKeys()
method, as shown...