Website Log-In Problem with Excel VBA, Selenium and Chromedriver

Viewed 1028

I have used VBA macros in Excel 2016 along with Chrome and Selenium WebDriver to log-in to many different websites, but I haven't been able to programmatically log into the AARP website with the following code.

' Open the "AARP" web page
WDriver.Start "chrome"
WDriver.Window.Maximize
WDriver.Get "https://www.medicare.uhc.com/AARP"

Application.Wait (Now + TimeValue("0:00:05"))   

' Find the "Sign In" button and click it
   Set Results = WDriver.FindElementsByTag("button")
    For Each itm In Results
        If InStr(1, itm.Text, "Sign In", vbTextCompare) > 0 Then
            itm.Click
            Exit For
        Else
        End If
    Next itm

' Wait until the page is fully loaded
Application.Wait (Now + TimeValue("0:00:10"))

' Enter Email address and PW and then click the Login button
WDriver.FindElementById("EMAIL").SendKeys ("")     ' focus
WDriver.FindElementById("EMAIL").SendKeys ("abcd")
Application.Wait (Now + TimeValue("0:00:02"))

WDriver.FindElementById("PASSWORD").SendKeys ("")  ' focus
WDriver.FindElementById("PASSWORD").SendKeys ("1234")
Application.Wait (Now + TimeValue("0:00:02"))

WDriver.FindElementById("submitBtn").Click

' Do stuff

I can see that the EMAIL address and PASSWORD are correct and inserted in the proper textboxes, but when the submit button is clicked a little wheel spins for a fraction of a second, but the unchanged webpage remains showing my email and pw.

If I now manually type in my correct email and pw, the little wheel spins again for a second, but again, nothing happens - no error message, nothing. The page can no longer be interacted with. If I want to try something else I need to close the webpage and start from the beginning with a new instance of Chrome.

If I start from the beginning and manually insert my email and pw, the website logs me in just fine. If I manually enter an incorrect email and pw I get the following message,

"Error: The username and password combination entered does not match our records."

What code will successfully insert the username and password so that it can be processed by the web page? You'll know that your code works when you get the error message shown above

The source code for the EMAIL input box is

<input id="EMAIL" class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" type="text" name="EMAIL" ng-model="sm.userInput" placeholder="" required="required" ng-blur="isValidUserNameEmail()" aria-invalid="true" data-nlok-ref-guid="345cd641-a989-4cee-a891-7e7cb5e43669">

The source code for the PASSWORD input box is very similar.

1 Answers

The issue is the website, some websites these days are blocking automation for various reasons. So, you have to trick them into thinking your not. The below link does a great job of explaining how to solve this, I've done some of these before with python, but with vba selenium being outdated I'd go with the second choice on the website: "Obfuscating JavaScript of Browser Driver EXE".

Essentially you edit your ChromeDriver in a text editor (C:\Users$User$\AppData\Local\SeleniumBasic). Then search for the following text: "$cdc_asdjflasutopfhvcZLmcfl_". Once you find it replace it with something like "$btlhsaxJbTXmBATUDvTRhvcZLm_" or anything of the same length. I tested it prior to doing this and was getting the same error as you were, after I was able to log in.

https://piprogramming.org/articles/How-to-make-Selenium-undetectable-and-stealth--7-Ways-to-hide-your-Bot-Automation-from-Detection-0000000017.html

Related