-1

I have found that the "Send_Keys" is not working for the following website due to the error "AttributeError: 'list' object has no attribute 'send_keys'".. Kindly note that I am using 'pycharm' editor

https://login.salesforce.com/?locale=eu

driver.find_elements_by_css_selector("input[id='username']").send_keys("testusername")

But the same command is working perfectly when using for the following

https://rahulshettyacademy.com/angularpractice/

driver.find_element_by_css_selector("input[name='name']").send_keys("testname")
2
  • 1
    Please refer to this question: stackoverflow.com/questions/29957373/… Commented Dec 1, 2020 at 5:05
  • The first one calls find_elements_by_css_selector, which returns a list of found elements. The second one calls find_element_by_css_selector, which returns a single element. Commented Dec 1, 2020 at 5:07

1 Answer 1

0
driver.find_elements_by_css_selector("input[id='username']").send_keys("testusername")

retruns a list , and send_keys is a method of webelement and not a list. So to send value to specific element call that element from the list

driver.find_elements_by_css_selector("input[id='username']")[0].send_keys("testusername")

On the other hand

driver.find_element_by_css_selector("input[id='username']").send_keys("testusername")

finds the first webelement matching the xpath locator so sendkeys works

Sign up to request clarification or add additional context in comments.

Comments

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.