Website says my browser is out of date when I try to automate my login process with Selenium

794 Views Asked by At

This is my first stackoverflow post so please excuse any posting nuances I may fail to observe. The issue I'm running in to is regarding automating a login process to my credit card website using Selenium and Python (v 3.11). My overall goal is to simply login to my credit card website (Discover CC website), navigate to a "statements" page, download my current statement as a CSV file, and further manipulate it with other Python code, and run this on a scheduled basis (thinking once a week). However I'm stuck at the automated login process. The Discover site tells me my browser is out of date, which can lead to security risks and that my account is temporarily unavailable. This is currently where I'm stuck.

What I've tried so far is shown in the code attached below. Lines 18 and 20 were of course removed for security reasons, but contain my correct username and password for the website.

#import stuff
import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
s = Service('C:\Program Files (x86)\chromedriver_win32\chromedriver.exe')
opts = Options()
opts.accept_insecure_certs = True
# opts.add_argument("--headless")
# assert opts.headless  # Operating in headless mode
browser = Chrome(service=s, options=opts)
browser.get('https://portal.discover.com/customersvcs/universalLogin/ac_main')
browser.implicitly_wait(10)
time.sleep(3)
userID = browser.find_element(By.ID, 'userid-content')
userID.send_keys('myUserName')
password = browser.find_element(By.ID, 'password-content')
password.send_keys('myPassword')
browser.implicitly_wait(10)
time.sleep(3)
# userID.submit()
clickSubmit = browser.find_element(By.ID, 'log-in-button')
browser.implicitly_wait(10)
clickSubmit.submit()

When I run this, it takes me to the correct website in the expected browser (Chrome), for which I have downloaded what I believe to be the correct chromedriver (Chrome version is a 109.0.5414.120, chromedriver is a 109.x.xxxx.xxx release number as well, but didn't match version of Chrome exactly), and it correctly enters my username and password, but gives me an "need to update browser"-esque error.

What I'm trying to iron is:

  • Is there an issue with my code that I'm using / how I'm accessing the site?
  • Is this a cookies/SSL certificate issue where I just need to make my browser "think" I'm a real user instead of some automated test software like it states is controlling chrome in a banner at the time when it launches using this code?
  • Is this code performing as it should, it's just the anti-bot security of this website, given it's a CC/financial website, that's just really good at detecting bots and keeping them from logging in to their site, even when presenting the correct username/password on the first attempt.

I've tried the same method above but with other libraries (e.g. undetected_chromedriver, selenium-stealth) and have the same result/issue, with the exact error message of:

"Your account cannot currently be accessed. Outdated browsers can expose your computer to security risks. To get the best experience on Discover.com, you may need to update your browser to the latest version and try again.

For questions, please contact us at 1-800-347-7769. We're always available 24 hours a day, 7 days a week."

Thank you for any/all help and input you all may have, I'm also a novice when it comes to Python/HTML, so apologies if this is an obvious issue/answer, I was using this idea solely as a learning opportunity.

Thanks!

2

There are 2 best solutions below

0
On

Without the proper error stacktrace and/or access to the relevant HTML it is tough to comment on the error:

Your account cannot currently be accessed. Outdated browsers can expose your computer to security risks. To get the best experience on Discover.com, you may need to update your browser to the latest version and try again.

However as per support.mozilla.org and reddit it appears as a discover.com site issue.


Improvements

Having said that there are a couple of improvements which you can incorporate as follows:

  • Replace the instances of browser.implicitly_wait(x) and time.sleep(y) with WebDriverWait

  • Locate the clickable elements inducing WebDriverWait for the element_to_be_clickable() as follows:

    driver.get('https://portal.discover.com/customersvcs/universalLogin/ac_main')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userid-content"))).send_keys("[email protected]")
    driver.find_element(By.CSS_SELECTOR, "input#password-content").send_keys("SageHerrin")
    driver.save_screenshot("login.png")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

login.png

0
On

Had the same issue, with driver v122 (current stable). Installed and used undetected_chromedriver, and it now works. So it does seem to be that Discover is trying to detect and prevent bots from logging in.

import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = uc.Chrome(headless=False, use_subprocess=False)
driver.get('https://portal.discover.com/customersvcs/universalLogin/ac_main')
WebDriverWait(driver, 20).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userid-content"))
).send_keys("username")
driver.find_element(
    By.CSS_SELECTOR, "input#password-content").send_keys("password")