Issue
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()
Solution
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
Answered By - user13914826
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.