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.
Here we will explore the clear()
, sendKeys()
, submit()
and click()
methods of the WebElement
interface.
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();