PDA

View Full Version : VBA to select multiple web pages



oam
06-15-2017, 07:40 PM
I am trying to use the HTML and VBA code below to login and select multiple buttons and links but I do not know VBA with HTML code. I got the VBA login part to work but I cannot navigate to the next page which is “Shipping Services” button. Does anyone know if the below code will work and how to make the below code navigate to the “Shipping Services” page.

Thank you for any and all help.


<div class="vtabs-tab-column"> <ul class="tabs-slider"> <li class="closed" id="url_v_menu_item_1"> <a class="closed" id="url_v_menu_item_1" href="/eAdmin/action/homepage" title="Welcome" tabindex="21"> Welcome </a> </li> <li class="closed" id="url_v_menu_item_2"> <a class="closed" id="a_v_menu_item_2" href="/eAdmin/action/inbox" title="Inbox" tabindex="22"> Inbox </a> </li> <li class="closed" id="url_v_menu_item_3"> <a class="closed" id="a_v_menu_item_3" href="/eAdmin/action/addservice/mailingServices" title="Mailing Services" tabindex="23"> Mailing Services </a> </li> <li class="closed" id="url_v_menu_item_4"> <a class="closed" id="a_v_menu_item_4" href="/eAdmin/action/addservice/shippingServices" title="Shipping Services" tabindex="24"> Shipping Services </a> </li>



Option Explicit
Sub MyGmail()
Dim htmlDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim ULogin As Boolean, ieForm
On Error GoTo Err_Clear
MyURL = "https://gateway.usps.com/eAdmin/view/signin"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set htmlDoc = MyBrowser.document
htmlDoc.all.UserName.Value = "Login" 'Enter your id here
htmlDoc.all.Password.Value = "Password" 'Enter your password here
For Each MyHTML_Element In htmlDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "button" Then MyHTML_Element.Click: Exit For
Next

With MyBrowser.document

For Each MyHTML_Element In htmlDoc.getElementsByClassName("closed") 'TagName("input")

If (MyHTML_Element.getAttribute("href") = "/eAdmin/action/addservice/shippingServices") Then
MyHTML_Element.Click
Exit For
End If

Next MyHTML_Element

End With

Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub

oam
06-16-2017, 05:22 PM
Can read the HTML code better this way. I am trying to select "Shipping Services" below.


<div class="vtabs-tab-column"> <ul class="tabs-slider">
<li class="closed" id="url_v_menu_item_1">
<a class="closed" id="url_v_menu_item_1"
href="/eAdmin/action/homepage" title="Welcome" tabindex="21">
Welcome
</a>
</li>
<li class="closed" id="url_v_menu_item_2">
<a class="closed" id="a_v_menu_item_2"
href="/eAdmin/action/inbox" title="Inbox" tabindex="22">
Inbox
</a>
</li>
<li class="closed" id="url_v_menu_item_3">
<a class="closed" id="a_v_menu_item_3"
href="/eAdmin/action/addservice/mailingServices" title="Mailing Services" tabindex="23">
Mailing Services
</a>
</li>
<li class="closed" id="url_v_menu_item_4">
<a class="closed" id="a_v_menu_item_4"
href="/eAdmin/action/addservice/shippingServices" title="Shipping Services" tabindex="24">
Shipping Services
</a>
</li>
<li class="closed" id="url_v_menu_item_6">
<a class="closed" id="a_v_menu_item_6"
href="/eAdmin/action/addservice/otherServices" title="Other Services" tabindex="26">
Other Services
</a>
</li>
<li class="closed" id="url_v_menu_item_7">
<a class="closed" id="a_v_menu_item_7"
href="/eAdmin/action/resources/support" title="Support" tabindex="27">
Support
</a>
</li>
<li class="closed" id="url_v_menu_item_8">
<a class="closed" id="a_v_menu_item_8"
href="/eAdmin/action/preferences" title="Manage Account" tabindex="28">
Manage Account
</a>
</li>
</ul>
</div>