0

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 successful logging into the website shown in 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"))   

' Click the "Sign In" button
WDriver.FindElementByXPath("/html/body/div[4]/div/div[1]/div[2]/div/div/div/main/section/div/div[1]/div/button[1]").Click

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

' Login
WDriver.FindElementById("EMAIL").SendKeys ("")     ' focus
WDriver.FindElementById("EMAIL").SendKeys ("abc")
Application.Wait (Now + TimeValue("0:00:02"))

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

WDriver.FindElementById("submitBtn").Click

' Do stuff

I can see that the EMAIL address and PASSWORD are correctly inserted, but when the submit button is clicked I get the following error message from the website, "Error: The username and password combination entered does not match our records."

The source code for the EMAIL input box is

<input id="EMAIL" class="form-control ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" type="text" name="EMAIL" ng-model="sm.userInput" placeholder="" required="required" ng-blur="isValidUserNameEmail()" aria-invalid="true" style="">

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

An acquaintance has suggested that I need to use javascript (ExecuteScript) and then call "isValidUserNameEmail()" after setting the EMAIL.

I am at a loss on how to perform this step and would appreciate help on how to code this step. Also, what exactly is the "isValidUserNameEmail()" code doing? Is there a way to accomplish this without using javascript?

Thanks in advance for your help...Ron

ron
  • 1,456
  • 3
  • 18
  • 27

1 Answers1

0

I will answer the second part about what exactly is the "isValidUserNameEmail()" code doing:

As you can probably guess from the name, it is performing validation on the user input field it is called from via the angular ng-blur event.

You can find most of what you need to know in the js file https://www.healthsafe-id.com/controllers/login/login-ce5235a2c825372facef0f2b619e467a.js.

The function definition is at line 624. You will see that it calls a custom function that checks if the field is empty. It uses a conditional ternary operator (?) to the decide what to do based on the result of the is empty test. If empty it looks for a saved value otherwise it looks for the user input. Either way, it assigns the return to a variable that it then passes back to the same function to test if still empty i.e. ''. If no, you get '' assigned, if yes, it sets piEMAILError to the value returned from a custom function (an AEM component from Optum. United partner). It passes in EMUsernameRequired as the keyAEM argument.

There are a series of other function calls within this calling function e.g. line 208 and line 218. The result of these is to return default responses as outlined in https://www.healthsafe-id.com/content/healthsafeid/aarp/signin?HTTP_LANGUAGE=en.

Within the above link you will find Username is required as the default associated with key EMUsernameRequired_v2 and The username and password combination entered does not match our records associated with SigninFailedNoRecord_v2. The latter which is the response you are currently getting implying that the values are either wrong, or not recognised.

It's angular so it's all quite convoluted and you could keep digging and tracking but some decisions are likely server side. Basically, the initial function is called when the input field loses focus.


For getting to the login page it would be more robust to use a short css selector than a long xpath e.g.

.FindElementByCss(".login button").click
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • How did you identify ".login button" as the css selector, I don't see it in the source code? – ron Nov 11 '20 at 00:02
  • 1
    there is a button element with parent that has a class login (that is what the selector means). Try opening browser dev tools on the page (F12), then in Elements tab press Ctrl + F and put _.login button_ in the search box and hit enter. – QHarr Nov 11 '20 at 04:46
  • I see the class login, but when I search I get "no matches found" with Chrome. – ron Nov 11 '20 at 16:27
  • can I have the url you are currently using? Perhaps I am ending up with a different – QHarr Nov 11 '20 at 17:24
  • I'm using https://www.medicare.uhc.com/AARP, same as shown above in my question. Your FindElementbyCss(".login button").click statement shown above does work, I just can't find ".login button" anywhere. – ron Nov 11 '20 at 19:42
  • It is there. Where you searching in the elements tab? [1](https://stackoverflow.com/a/56345695/6241235) – QHarr Nov 11 '20 at 19:51
  • 1
    Ah, I was using a different search (the one in "Customize and control developer tools"). Now I see it, thanks for working with me. – ron Nov 11 '20 at 20:16