简体   繁体   中英

AttributeError: module 'selenium.webdriver' has no attribute 'find_element'

I've been trying to get Python to login to a website and download a csv file (one after the other because they can take a long time, and they can't be downloaded in parallel). I can't click SENECA01 button because of ElementClickInterceptedException, so after reading stackoverflow I tried using an explicit wait.

Here's the error:

AttributeError: module 'selenium.webdriver' has no attribute 'find_element'

Here's the code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from getpass import getpass
from selenium.webdriver.common.by import By
import time

opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
opt.add_argument("--disable-extensions")
# Pass the argument 1 to allow and 2 to block
opt.add_experimental_option("prefs", { \
    "profile.default_content_setting_values.media_stream_mic": 1, 
    "profile.default_content_setting_values.media_stream_camera": 1,
    "profile.default_content_setting_values.geolocation": 1, 
    "profile.default_content_setting_values.notifications": 1 
  })

PATH = ("C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python39\\chromedriver.exe")
driver = webdriver.Chrome(PATH, chrome_options=opt)
wait = WebDriverWait(webdriver, 5)

driver.get("https://xxxx.xxx-xxx.org/logon/login")
print(driver.title)

username = input("Enter in your username: ")
password = getpass("Enter your password: ")

username_textbox = driver.find_element_by_id("username")
username_textbox.send_keys(username)

password_textbox = driver.find_element_by_id("password")
password_textbox.send_keys(password)

login_button = driver.find_element_by_class_name("formstylebut")
login_button.submit()

link = driver.find_element_by_link_text("Big Data (CAD)")
link.click()

link = driver.find_element_by_link_text("Run a Report")
link.click()

link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "SENECA01")))
link = driver.find_element_by_link_text("SENECA01")
link.click()

This

wait = WebDriverWait(webdriver, 5)

should be

wait = WebDriverWait(driver, 5)

and this is how you should use this

link = wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "SENECA01")))

trust it helps!

To start using Selenium first and foremost you need:

from selenium import webdriver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM