Home > Back-end >  driver.send_keys("Selenium") AttributeError: 'WebDriver' object has no attribute
driver.send_keys("Selenium") AttributeError: 'WebDriver' object has no attribute

Time:01-10

I've been trying to input text in google textbox. Suddenly got this error. Is something modified/changed in selenium newly? Code:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Chrome(executable_path="C:\\Program Files (x86)\\chromedriver.exe")
driver.get("https://www.google.com/")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located(By.NAME, "gLFyf")
    )
finally:
    driver.send_keys("Selenium")

error:

  File "C:\Users\bhatt\OneDrive\Desktop\Sublime\gotta_master_selenium.py", line 15, in <module>
    driver.send_keys("Selenium")
AttributeError: 'WebDriver' object has no attribute 'send_keys'

I also have some more errors

```EC.presence_of_element_located(By.NAME, "gLFyf")TypeError: presence_of_element_located() takes 1 positional argument but 2 were given

I've been looking for solution throughout the vacation. Still can't figure out the solution

CodePudding user response:

You can not send text send_keys("Selenium") to a web driver object driver.
Text should be sent to a specific web element you need to locate with the driver

CodePudding user response:

For first error:

You have to use send_keys() function with webelement not with webdriver.

Syntax:

driver.find_element(<locator type like By.XPATH or By.ID or...>, <locator value>).send_keys("<value to enter>")

For second error:

You have to use one more parenthesis '()' in the below line:

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "gLFyf")))
  • Related