Home > OS >  How cani fix the send_keys Attribute Error?
How cani fix the send_keys Attribute Error?

Time:08-31

I am trying to write a search on the google search bar.

import time

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("C:\\Users\\HP\\PycharmProjects\\SeleniumTest1\\Drivers\\chromedriver.exe")
driver.get("https://www.google.com/")
driver.maximize_window()
driver.find_element_by_name("q").send_keys("LinkedIn login")
driver.find_element_by_name("q").send_keys(Keys.ENTER)
driver.find_element_by_partial_link_text("LinkedIn Login").click()
driver.find_element_by_id("username").send_keys("enter your username")
driver.find_element_by_id("password").send_keys("enter your password")
driver.find_element_by_tag_name("button").click()
time.sleep(5)
print(driver.title)
print(driver.current_url)
driver.close()

This is the error I keep getting from the console

driver.find_element_by_name("q").send_keys("LinkedIn login")
AttributeError: 'NoneType' object has no attribute 'send_keys'

CodePudding user response:

The current selenium version uses find_element() to get elements. Try the code below. Change the by attribute to the one you are searching with

driver.find_element(by="name", value = "q").send_keys("LinkedIn login")
  • Related