VBA code to select website drop down opion

Joined
Jul 28, 2014
Messages
2
Reaction score
0
I am trying to login to a website using excel VBA, which opening page has a drop down menu to select the option that will bring the login page containing the data I need. My problem is writing the code for automating the drop down menu selection. Portion of the VBA code I am using as well as the website HTML code is below. Any help will be greatly appreciated.

VBA code:

Sub CapOne()

Dim i As Long
Dim ie As Object
Dim objElement As Object
Dim objCollection As Object

'Create InternetExplorer Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://www.capitalone.com"

' Wait while IE loading...
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set objCollection = ie.document.getElementsByTagName("input")

'--------------Code for drop down menu selection - (code does not work) -------------
i = 0
While i < objCollection.Length
If objCollection(i).Type = "button" And objCollection(i).Name = "enter name" Then
Set objElement = objCollection(i)
objElement.Click
GoTo 50
Else
i = i + 1
End If
Wend
'-------------------Code for login – (this code works) --------------------
50 i = 0
While i < objCollection.Length
If objCollection(i).Name = "us-credit-cards-uid" Then
objcoval = objCollection(i)
objCollection(i).Value = "username"
GoTo 100
Else
i = i + 1
End If
Wend

100 i = 0
While i < objCollection.Length
If objCollection(i).Name = "us-credit-cards-pw" Then
objCollection(i).Value = "Password"
GoTo 200
Else
i = i + 1
End If
Wend

200 i = 0
While i < objCollection.Length
If objCollection(i).Type = "submit" And objCollection(i).Value = "Sign In" Then
Set objElement = objCollection(i)
objElement.Click
GoTo 500
Else
i = i + 1
End If
Wend
GoTo 600
500 Do While ie.Busy


HTML code:

<h2>Account Sign In</h2>
<fieldset class="select-account">
<legend><span>Select an Account Type</span></legend>
<button type="button" id="btnAccountType" name="btnAccountType" class="active-account">Select an account type&hellip;</button>
<ul class="account-types" role="menu">
<li role="presentation">
<input type="radio" id="rbCreditCards" name="rbAccountType" value="auth-credit-cards" />
<label role="menuitemradio" for="rbCreditCards">Credit Cards</label>
</li>
<li role="presentation">
<input type="radio" id="rbBanking" name="rbAccountType" value="auth-banking" />
<label role="menuitemradio" for="rbBanking">Banking <em>including Capital One 360</em></label>
</li>
<li role="presentation">
<input type="radio" id="rbAutoLoans" name="rbAccountType" value="auth-auto-loans" />
<label role="menuitemradio" for="rbAutoLoans">Auto Loans</label>
</li>
<li role="presentation">
<input type="radio" id="rbInvesting" name="rbAccountType" value="auth-sb" />
<label role="menuitemradio" for="rbInvesting">ShareBuilder Investing</label>
</li>
<li role="presentation">
<input type="radio" id="rbHomeLoans" name="rbAccountType" value="auth-hl" />
<label role="menuitemradio" for="rbHomeLoans">Home Loans</label>
</li>
<li role="presentation">
<input type="radio" id="rbMoreProducts" name="rbAccountType" value="auth-more-products" />
<label role="menuitemradio" for="rbMoreProducts" class="more-products">More Products</label>
</li>
<li role="presentation" class="off">
<input type="radio" id="rbTreasury" name="rbAccountType" value="auth-treasury-optimizer" />
<label role="menuitemradio" for="rbTreasury">Treasury Optimizer</label>
</li>
<li role="presentation" class="off">
<input type="radio" id="rbRewards" name="rbAccountType" value="auth-rewards" />
<label role="menuitemradio" for="rbRewards">Rewards</label>
</li>
<li role="presentation" class="off last"><a class="asset-link" data-href="no-account" role="menuitem" >Don't see your account?</a></li>
</ul>
<div class="auth-error account-type" id="auth-default-error-user">
<p><strong>Oops!</strong></p>
<p>Please select an account type</p>
</div>
</fieldset>
<div id="auth-default" class="auth">
<div class="field full">
<label for="default-uid">Username</label>
<input type="text" id="default-uid" maxlength="50" name="default-uid" data-aria-describedby="auth-default-error-user" aria-required="true" />
</div>
<input class="submit-btn c1-button small" type="submit" value="Continue" id="default-btn" name="default-btn" />
<p class="auth-help"> <span class="aria-help" id="lbl-default-user-forgot">Forgot Username link</span> <strong>Forgot</strong> <a href="#" id="default-user-forgot" aria-describedby="lbl-default-user-forgot">Username</a>?<br>
<a href="#" class="asset-link" data-href="no-account">Enroll here</a> </p>

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top