Interacting with Elements: Click, Type, Read and Verify
The Element Object
find_element returns a WebElement. You use its methods to act and its properties to read.
Actions
| Method | What it does |
|---|---|
click() | Click |
send_keys("text") | Type text |
clear() | Empty a text box |
submit() | Submit the form that contains the element (older style) |
send_keys(Keys.ENTER) | Press a special key |
python
from selenium.webdriver.common.keys import Keys
box = driver.find_element(By.NAME, "q")
box.clear()
box.send_keys("selenium python")
box.send_keys(Keys.ENTER)
| Special key | Use |
|---|---|
Keys.ENTER | Submit |
Keys.TAB | Move to next field |
Keys.ESCAPE | Close pop-up |
Keys.BACKSPACE | Delete a character |
Keys.CONTROL, 'a' | Select all (combination) |
Keys.PAGE_DOWN | Scroll |
python
box.send_keys(Keys.CONTROL, "a") # select all
box.send_keys(Keys.BACKSPACE) # delete
Reading Information
| Property | Returns |
|---|---|
element.text | Visible text (hidden text is empty) |
element.get_attribute("value") | Attribute such as value, href, class, placeholder |
element.get_dom_attribute("href") | The attribute exactly as written in HTML |
element.get_property("checked") | Live JavaScript property |
element.tag_name | input, div ... |
element.size | {'height': 40, 'width': 200} |
element.location | {'x': 10, 'y': 80} |
element.value_of_css_property("color") | A style value |
python
link = driver.find_element(By.LINK_TEXT, "Elemental Selenium")
print(link.text)
print(link.get_attribute("href"))
print(link.value_of_css_property("color"))
box = driver.find_element(By.ID, "username")
box.send_keys("ana")
print(box.get_attribute("value")) # text typed in the box (not .text!)
text vs value: For an input box,
.text is empty. The typed text is in get_attribute("value").
State Checks
| Method | True when |
|---|---|
is_displayed() | Element is visible |
is_enabled() | Element is not disabled |
is_selected() | Checkbox, radio or option is selected |
python
driver.get("https://the-internet.herokuapp.com/dynamic_controls")
checkbox = driver.find_element(By.CSS_SELECTOR, "#checkbox-example input")
print(checkbox.is_displayed()) # True
print(checkbox.is_selected()) # False
field = driver.find_element(By.CSS_SELECTOR, "#input-example input")
print(field.is_enabled()) # False (disabled at start)
Reading Many Elements
python
items = driver.find_elements(By.CSS_SELECTOR, ".inventory_item_name")
names = [i.text for i in items]
print(names)
assert names == sorted(names)
A Complete Example
python
driver.get("https://www.saucedemo.com")
driver.find_element(By.ID, "user-name").send_keys("standard_user")
driver.find_element(By.ID, "password").send_keys("secret_sauce")
driver.find_element(By.ID, "login-button").click()
assert "inventory" in driver.current_url
assert driver.find_element(By.CLASS_NAME, "title").text == "Products"
products = driver.find_elements(By.CLASS_NAME, "inventory_item")
print("Products on page:", len(products))
Typing Into Hidden or Special Fields
- Date fields often need a format such as
01012026or2026-01-01 - If
clear()does not work (React sites), useCtrl+AthenBackspace - If a click is intercepted by another element, wait for it to disappear or scroll (see waits and JavaScript lessons)
Conclusion
Use click, send_keys and clear to act, and text, get_attribute, is_displayed, is_enabled and is_selected to read and verify. Remember that typed input is in the value attribute.
Quick Summary: Act: click/send_keys/clear. Read: text/get_attribute. Check: is_displayed/is_enabled/is_selected.

