Home > other >  attributeerror: 'list' object has no attribute 'send_keys'. How do fix this?
attributeerror: 'list' object has no attribute 'send_keys'. How do fix this?

Time:11-13

I want to make automated login to router web GUI, but if I use input_tags.send_keys("PASSWORD"), then I get error

AttributeError: 'list' object has no attribute 'send_keys'.

Here is my code example

#imports
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

#login
driver = webdriver.Chrome()
driver.get('http://ROUTER_IP')
password = driver.find_elements(By.ID, "login_password")
password.send_keys("PASSWORD")

Here is webpage inspect picture:

webpage inspect picture

Here is my output:

AttributeError: 'list' object has no attribute 'send_keys'

I tried to Google this, but I found nothing.

CodePudding user response:

driver.find_elements returns you a list of elements. If you're certain there's only a single element that satisfiers your criterion, you can just use:

password = driver.find_elements(By.ID, "login_password")[0]

CodePudding user response:

In case there is only 1 element on that page having id = 'login_password' all you need to make your code working is to change from find_elements to find_element. Try this code:

#imports
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

#login
driver = webdriver.Chrome()
driver.get('http://ROUTER_IP')
password = driver.find_element(By.ID, "login_password")
password.send_keys("PASSWORD")
  • Related