1

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()

2 Answers 2

3

To start using Selenium first and foremost you need:

from selenium import webdriver

Additionally, as per the documentation the WebDriverWait is defined as follows:

class selenium.webdriver.support.wait.WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None)

Where the Constructor, takes a WebDriver instance and timeout in seconds.

As your webdriver instance is:

driver = webdriver.Chrome(PATH, chrome_options=opt)

So instead of webdriver you need to pass the same driver instance to the WebDriverWait() as follows:

wait = WebDriverWait(driver, 5)
Sign up to request clarification or add additional context in comments.

1 Comment

This made me realise I wasn't passing driver through the fixture's function. e.g. @pytest.fixture def do_something() { button = WebDriverWait(driver, 16, ignored_exceptions=StaleElementReferenceException)\ .until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button"))) button.click() } Should have been: @pytest.fixture def do_something(driver) { button = WebDriverWait(driver, 16, ignored_exceptions=StaleElementReferenceException)\ .until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button"))) button.click() } So thank you.
2

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!

4 Comments

Thanks for the response. So I tried that and got this instead - ElementClickInterceptedException: Message: element click intercepted: Element <a href="report_exec_hc_1.php?report_id=...">SENECA01</a> is not clickable at point (100, 740). Other element would receive the click: <td align="center" class="footer" bgcolor="Black">...</td>
I need at least 15 reputation to cast a vote, but I did upvote and tick and feedback has been recorded. I've actually already created a ticket for the second error, but it was closed because it's been "answered before". Never mind the fact that I'm really new to Python and this error/exception is really hard to get past. Thanks for your help nonetheless.
So I should just create a new ticket and tag selenium. I'll see if I can make the ticket different enough so that it will remain on StackOverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.