After identifying elements using locators, the next step is to interact with them. Selenium WebDriver provides methods to perform common user actions on web elements. In this section, let's see two of the basic interactions that can be performed in the web application using Selenium WebDriver very often.
Clicking an Element
To click on buttons, links, checkboxes or any clickable element in the webpage, use click()
Example
This code locates the elements that have an id “submit” and clicks it.
Typing into Input Fields
To enter text into an input field or text box, use sendKeys()
Example
This code types “admin” into the input field with the name “username”.
These are the two most common interactions used in automation testing. There are many other actions that can be performed using Selenium WebDriver, such as hovering, double-clicking, and selecting options from dropdowns. We will cover these in later sections.