selenium python send_key error: list object has no attribute

41,333

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.

Share:
41,333
rearThing
Author by

rearThing

Time is not made of days but instances

Updated on August 12, 2021

Comments

  • rearThing
    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
    sabi Otman about 5 years
    driver.find_element_by_xpath(".//*[@id='UserName']").send_ke‌​ys('username')
  • Tranbi
    Tranbi almost 3 years
    This has already been mentioned in in the accepted answer stackoverflow.com/a/29957417/13525512