2

I am trying to send_keys to a webelement but each time I do I get this error

driver.send_keys("admin")

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

from webdriver_manager.chrome import ChromeDriverManager from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains import time driver = webdriver.Chrome(executable_path=ChromeDriverManager().install()) driver.get("http://gs.login.com") cookies = driver.get_cookies() driver.implicitly_wait(15) driver.find_element_by_id('username') driver.send_keys("admin") time.sleep(10) driver.quit() 

I have look at documentation for selenium and I feel like have added the correct modules, but I still keep getting the same error message. Can someone please help.

2 Answers 2

1

send_keys() is an element method, not a webdriver method.

When you call find_element_by_id(), you have to save the returned element and then you can call send_keys() on that element.

username_element = driver.find_element_by_id('username') username_element.send_keys('admin') 
Sign up to request clarification or add additional context in comments.

Comments

1

You need to store the element in a variable first, and then send_keys against that

element = driver.find_element_by_id('username') element.send_keys("admin") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.