Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium python send_key error: list object has no attribute

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?

like image 563
rearThing Avatar asked Apr 30 '15 01:04

rearThing


2 Answers

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')
like image 94
Saifur Avatar answered Sep 30 '22 17:09

Saifur


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.

like image 34
oriolowonancy Avatar answered Sep 30 '22 18:09

oriolowonancy