selenium python send_key error: list object has no attribute
Solution 1
You are getting a List of webElements with driver.find_elements_by_xpath(".//*[@id='UserName']")
which of course not a single element and does not have send_keys()
method. use find_element_by_xpath
instead. Refer to this api doc.
userID = driver.find_element_by_xpath(".//*[@id='UserName']")
userID.send_keys('username')
Solution 2
instead of this:
userID = driver.find_elements_by_xpath(".//*[@id='UserName']")
userID.send_keys('username')
try:
userID = driver.find_element_by_xpath(".//*[@id='UserName']")
userID.send_keys('username')
I had the same issues and that worked for me.
Solution 3
I was facing the same problem while using to input for Instagram, tried the time module to sleep for 2 seconds then it started working for me. Problem was that before loading the website bot starts to find that path and report errors.
import time
time.sleep(2)
Solution 4
driver.find_element_by_xpath(".//*[@id='UserName']").send_keys('username')
find_element without s
.
![rearThing](https://i.stack.imgur.com/j0Zgu.jpg?s=256&g=1)
Comments
-
rearThing almost 3 years
Helo,
my xpath does validate in firePath but when I try to send _key I get an error.
userID = driver.find_elements_by_xpath(".//*[@id='UserName']") userID.send_keys('username')
AttributeError: 'list' object has no attribute 'send_keys'
Can someone toss me a bone please?
-
sabi Otman about 5 yearsdriver.find_element_by_xpath(".//*[@id='UserName']").send_keys('username')
-
Tranbi almost 3 yearsThis has already been mentioned in in the accepted answer stackoverflow.com/a/29957417/13525512