[英]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).我一直在尝试让 Python 登录网站并下载 csv 文件(一个接一个,因为它们可能需要很长时间,并且无法并行下载)。 I can't click SENECA01 button because of ElementClickInterceptedException, so after reading stackoverflow I tried using an explicit wait.
由于 ElementClickInterceptedException,我无法单击 SENECA01 按钮,因此在阅读了 stackoverflow 后,我尝试使用显式等待。
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:要开始使用 Selenium 首先您需要:
from selenium import webdriver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.