5

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?

9 Answers 9

17

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')
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

1

driver.find_element_by_xpath(".//*[@id='UserName']").send_keys('username')

find_element without s.

1 Comment

driver.find_element_by_xpath(".//*[@id='UserName']").send_keys('username')
1

Please replace your code with the following code because you like addressing the first component of your list, not whole list.

userID = driver.find_elements_by_ID('username')[0]

userID.send_keys('username')

or delete "s" from find_elements_by_ID such as follow:

userID = driver.find_element_by_ID('username')

userID.send_keys('username')

Comments

1

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)

Comments

0

This error occurs when one tries to perform action on list instead of element. I was getting similar error when I was trying to click on button to submit credentials. I found the work around by emulating pressing enter key on keyboard. e.g. find any element on page using xpath/css, etc. and send enter key.
driver.find_element_by_id('test_id').send_keys(Keys.ENTER)

Comments

0

I had the same problem - so I just did:

userID[0].send_keys('username')

Worked for me

Comments

0
from selenium import webdriver
from selenium.webdriver.common.by import By

userID = driver.find_elements( By.XPATH, "//div[@title='Username']")
userID[0].send_keys('username')

Comments

-2

when we select multiple element we type elements (s), its return a list. that have no "send_keys" single element have no s. that have "send_keys"

1 Comment

This has already been mentioned in in the accepted answer stackoverflow.com/a/29957417/13525512

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.