Trying to login into website from VBA - can do it for other sites, but this one needs something different

rlm1111

New Member
Joined
Mar 29, 2016
Messages
3
I've used this VBA subroutine to login into another site, and it's working ok. At the site at the URL below, the userid and password fields are populated with the correct values, but I can't seem to create code that will click the login button. Clicking it manually works, so my userid or password aren't corrupted. I've tried many things, as you can see - even SendKeys! I've included the HTML below my code, the login button is the last element at the end. Any help on clicking that button would be really appreciated - I don't have much hair left!!! :)

@@@@@@@@@@ My Code @@@@@@@@@@@@@@@
Code:
Sub GetAmazonStoreCardBalance()

 Dim MyHTML_Element As IHTMLElement
 Dim MyURL As String
 Dim sBalance As String
 
 On Error GoTo Err_Clear
 
 MyURL = "https://www.synchronycredit.com/eSecurity/Login/login.action?clientId=amazon&accountType=plcc&langId=en"
 Set MyBrowser = New InternetExplorer
 MyBrowser.Silent = True
 MyBrowser.Visible = True
 MyBrowser.Navigate MyURL
 
 Do   'wait for page to load
 Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
 Set HTMLDoc = MyBrowser.Document
 
 ' the login page shows up first, so we enter our login info
 HTMLDoc.all("loginUserID").Value = "my userid"
 HTMLDoc.all("loginPassword").Value = "my password"

 ' this code worked for me for a different website, but won't work here
 For Each MyHTML_Element In HTMLDoc.getElementsById("secLoginButton")
    If MyHTML_Element.Type = "button" Then
        MyHTML_Element.Click
        Exit For
    End If
  Next

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' here's some other things I've tried:

' let' try finding it by Class
'  For Each MyHTML_Element In HTMLDoc.getElementsByClass("pull-right mTop20 mRight30 mLeft80")
     ' let's try clicking EVERY element in this outer element
'    MyHTML_Element.Click
' Next

 ' this code worked for somebody else, let's try it
 ' HTMLDoc.forms(0).submit
 
 ' another variation I found online
 ' HTMLDoc.forms(1).submit

  ' let's trying tabbing to the button, and then send an 'enter' - I tried a number of different tabs
 'For x = 1 To 6
 '   SendKeys "{TAB}", True
 'Next x
 'SendKeys "{ENTER}", True
 
 ' let's add some wait time, to see if the next page will load
 'Do   'wait for page to load
 'Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  the rest of this code works fine...
 
 ' first we get all the tags
 Dim tag
 Dim tags As Object
 Set tags = MyBrowser.Document.getElementsByTagName("*")
 
 ' then we go thru them to find the text that displays the balance
 For Each tag In tags
    If tag.className = "activityPayment" Then  ' we found it
      ' parse out the dollar value of the balance
      sBalance = tag.innerText
      sBalance = Right(sBalance, Len(sBalance) - InStr(sBalance, "$") - Len("$") + 1) ' search forward to just past the dollar sign
      sBalance = Left(sBalance, InStr(sBalance, "*") - 1) ' snip off everything after the cents
      sBalance = Left(sBalance, Len(sBalance) - 4) & "." & Right(sBalance, 2) ' replace weird symbol with decimal point
      ' MsgBox sBalance
      Range("AmazonStoreCardBalance") = sBalance ' copy the dollar amount into the proper cell of the spreadsheet
      Exit For
    End If
 Next tag
 Set HTMLDoc = Nothing
 
 FlashRange Range("AmazonGiftCardBalance"), 4
 WAVPlay (SoundFileFolder + "qopen2.wav")

Err_Clear:  ' this code apparently lets us ignore random insignificant errors that often occur
 If Err <> 0 Then
    Err.Clear
    Resume Next
 End If

End Sub

@@@@@@@@@@@@@@@@@@@@ HTML code snippet I've been working with @@@@@@@@@@@@@@@@@@@




<label for="loginUserID" class="labelMargin loginLabel">
User ID
</label>


044808.png

<input name="userName" maxlength="50" value="" id="loginUserID" class="fullWidth ensightenEvent" aria-describedby="loginUserIDdes loginUserIDdes1" data-type="field" data-reason="login" type="text">




Case-sensitive, may differ from your Amazon.com User ID









<label for="loginPassword" class="labelMargin loginLabel">
Password
</label>


044806.png

<input name="password" maxlength="20" id="loginPassword" class="fullWidth ensightenEvent" aria-describedby="loginPassworddes" data-type="field" data-reason="password" type="password">









<input class="customInput ensightenEvent" id="rememUID" aria-describedby="rememUIDdes" *******="javascript:setRememberMeFlag(this.id);" data-reason="login:start:remember user id" data-type="field" type="checkbox">
<label for="rememUID" class="pull-left rememberme" id="rememUIDdes">Remember User ID</label>






<a href="javascript<strong></strong>:loginSubmit('../Login/loginSubmit.action', 'loginForm');" title="Login to your account" id="secLoginBtn" data-reason="login:start:submit" data-type="button"
class="btn secLoginBtn secureLockImg ensightenEvent">
044828.png
Secure Login






@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Here's the HTML code, it didn't come out in my post as code:

<div class="pull-left mTop10"><br />
<div class="userID errorMsgLabel err_message" role="alert" id="loginUserIDdes1"style="margin-bottom: 0.5rem; margin-left: 80px;"><br />
<br />
</div><br />
<label for="loginUserID" class="labelMargin loginLabel"><br />
User ID<br />
</label><br />
<div class="pull-left inputFields fullWidth"><br />
<div class="fullWidth logUserId"><br />
<span><img src='../../essimages/cs/groups/ess_webasset/generic/@common/en/brandimages/044808.png' alt="User ID Image" /></span><br />
<input type="text" name="userName" maxlength="50" value="" id="loginUserID" class="fullWidth ensightenEvent" aria-describedby="loginUserIDdes loginUserIDdes1" data-type="field" data-reason="login"/><br />
</div><br />
<br />
<p class="helpText pull-left" id="loginUserIDdes"><br />
Case-sensitive, may differ from your Amazon.com User ID<br />
</p><br />
</div><br />
</div><br />
<div class="pull-left mTop20"><br />
<div class="loginPasswordMessage errorMsgLabel err_message" role="alert" id="loginPassworddes" style="margin-bottom: 0.5rem; margin-left: 80px;"><br />
<br />
</div><br />
<label for="loginPassword" class="labelMargin loginLabel"><br />
Password<br />
</label><br />
<div class="pull-left inputFields fullWidth"><br />
<div class="fullWidth logPassword"><br />
<span><img src='../../essimages/cs/groups/ess_webasset/generic/@common/en/brandimages/044806.png' alt="Password security lock image" /></span><br />
<input type="password" name="password" maxlength="20" id="loginPassword" class="fullWidth ensightenEvent" aria-describedby="loginPassworddes" data-type="field" data-reason="password"/><br />
</div><br />
</div><br />
</div><br />
<div class="pull-left mTop20 mLeft80"><br />
<div class="customControl"><br />
<br />
<input type="checkbox" class="customInput ensightenEvent" id="rememUID" aria-describedby="rememUIDdes" *******="javascript:setRememberMeFlag(this.id);" data-reason="login:start:remember user id" data-type="field" /><br />
<label for="rememUID" class="pull-left rememberme" id="rememUIDdes"><span>Remember User ID</span></label> <br />
</div><br />
</div><br />
<div class="pull-right mTop20 mRight30 mLeft80"><br />
<p><br />
<a href="javascript:loginSubmit('../Login/loginSubmit.action', 'loginForm');" title="Login to your account" id="secLoginBtn" data-reason="login:start:submit" data-type="button"<br />
class="btn secLoginBtn secureLockImg ensightenEvent"><img class="pull-left" src='../../essimages/cs/groups/ess_webasset/generic/@common/en/brandimages/044828.png' alt="Login security lock image"/>Secure Login</a><br />
</p><br />
</div><br />
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top