Python中 AttributeError: 'list' object has no attribute 'send_keys' 解決方法


往輸入框中輸入用戶名和密碼,報了一個錯:AttributeError: 'list' object has no attribute 'send_keys'

這是報錯的代碼:

driver.find_elements_by_name("account").send_keys("admin")
# 用Tab鍵把光標移動到密碼輸入框
driver.find_elements_by_name("account").send_keys(Keys.TAB)
time.sleep(8)
driver.find_elements_by_name("password").send_keys("123456")
# 使用Enter鍵按鈕
driver.find_elements_by_name("password").send_keys(Keys.ENTER)

解決辦法:將 find_elements_by_name 改為 find_element_by_name

原因:find_elements是查找到多個符合條件的元素,返回一個列表,列表沒有“send_keys"這種屬性,所以報錯;

      find_element是查找到第一個符合條件的元素,返回一個對象。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM