Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'selenium.webdriver.common.keys' has no attribute 'RETURN'

Why the error message is showing when I run the following code? I also used ENTER key instead of RETURN, but then error showed:

"ImportError: cannot import name 'keys' from 'selenium.webdriver.common.keys"

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


PATH  = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://www.dr-chuck.com/csev-blog/?s=soup")
print(driver.title)

search = driver.find_element_by_id("s")
search.send_keys("soup")
search.send_keys(keys.RETURN)



try:
    main = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "main"))
    )
    articles = main.find_element_by_tag("article")
    for artiicle in articles:
        header = article.find_element_by_tag("a")
        print(header.text)

finally:
    driver.quit()
like image 918
Muktadir Avatar asked Apr 06 '26 17:04

Muktadir


1 Answers

Try changing this:

from selenium.webdriver.common.keys import keys

It's should:

from selenium.webdriver.common.keys import Keys

Note the uppercase K on Keys