Selenium + Python · Lesson 17 of 43
Module 17: WebElement
Your task
Implement safe_type(element, text_to_enter):
Write it in the editor, then press Check answer (Ctrl + Enter).
username_field = driver.find_element(By.ID, "username")
# Input operations:
username_field.clear()
username_field.send_keys("sdet_python")
# Reading attributes & states:
val = username_field.get_attribute("value")
is_visible = username_field.is_displayed()
is_active = username_field.is_enabled()WebElement objects represent the HTML nodes you interact with on the page. In this lesson, you will learn to send keys, clear inputs, read element text and attributes, and check visibility before interacting. Let's master WebElement!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
Text typed into inputs lives in the 'value' HTML attribute. Use element.get_attribute('value') to retrieve input text.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___