1

TLDR: Please skip the first paragraph and go to the second paragraph for the technical issue.

I'm trying to automate the downloads of csv files which have financial data of several clients for each month. The downloads take longer the deeper in the year you go because for example the March report will have financial data from January to March; the April report will have financial data from January to April and so on. It's not an ideal process and although I can't change the speed of downloads I can't at least automate the process so it saves me time wasted just clicking here then there and logging in and logging in over and over again and I don't have to try to remember which client I downloaded (the filenames are just random numbers and letters). I'm running this on Jupyter Notebook and have just been building this code by watching Youtube tutorials and using stackoverflow to overcome any hurdles. A healthy lot of copy and paste in this thing for sure. Ok so today I ran into something that I just can't get past.

I can't click SENECA01 because it was clicking something else so one of the suggestions was to use a Wait (I think it's an explicit Wait) - that's what the "try" and "finally" block is for. I get an error though:

MaxRetryError: HTTPConnectionPool(host='localhost', port=65376): Max retries exceeded with url: /session/e6c590c385ed1420632a934363594ee3/element (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000015061B83DC0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

Here's the code:

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)

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


try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.LINK_TEXT, "SENECA01"))
    )
finally:
    driver.quit()

link = driver.find_element_by_link_text("SENECA01")
link.click()
Optik
  • 33
  • 2
  • 7

0 Answers0