17. WebElement Operations: Typing, Clicking & State Checks

Interacting with WebElements

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()

Task

  • Implement safe_type(element, text_to_enter):
  • 1. If element is_displayed() and is_enabled():
  • - element.clear()
  • - element.send_keys(text_to_enter)
  • - return True
  • 2. Return False otherwise.
πŸ’‘Common doubts
Did you like the problem?
Lesson 17 of 43
Python
Loading code editor…
Next