Reputation: 89
This is the code I have
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://website.com")
element_user = driver.find_elements_by_id("user").send_keys("name123")
I keep getting this error
element_user = driver.find_elements_by_id("user").send_keys("")
AttributeError: 'list' object has no attribute 'send_keys'
Upvotes: 0
Views: 48
Reputation: 50949
find_elements_*
returns a list, for a single WebElement
use find_element_*
. In addition, send_keys()
doesn't have return
statement so it returns default None
. Split the command to two lines or remove the assignment
driver.find_element_by_id("user").send_keys("name123")
# or
element_user = driver.find_elements_by_id("user")
element_user.send_keys("name123")
Upvotes: 1
Reputation: 10782
You are using find_elements_by_id
notice the s
in elements
.
DOCS (epmhasis mine)
Returns:
list of WebElement - a list with elements if any was found. An empty list if not
There's also a method find_element_by_id
, that returns a single element if found.
Upvotes: 2