2

I programmed an automated process written in VBA that takes thousands of origin and destination zip codes from customers and gathers prices from my rail providers using VBA and Excel. One provider in particular recently updated their page to require we select a city/state combo after entering either origin/destination zip code.

I can enter the zip and such fine; however, I can't figure out how to select the list item after doing so. Below is the HTML from the website.

InputBox for the Zipcode

Here is my code putting in the zip: (I have the Select in there with hopes of presenting the ul table up)

ieDoc.all.shipFromLocation.Value = oZip
ieDoc.all.shipFromLocation.Select
ieDoc.all.shipToLocation.Value = dZip
ieDoc.all.shipToLocation.Select

After the Zip codes are entered this ul box will appear:

<ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content ui-corner-all location-ac-menu" id="ui-id-1" tabindex="0" aria-disabled="false" style="display: none; width: 222.77777767181396px; top: 260.34715270996094px; left: 164.01385498046875px;">
<li><strong class="location-ac-heading">Please select:</strong></li>
<li class="ui-menu-item" role="presentation"><a id="ui-id-87" class="ui-corner-all" tabindex="-1">PHILA, PA 19106 US</a></li>
<li class="ui-menu-item" role="presentation"><a id="ui-id-88" class="ui-corner-all" tabindex="-1">WM PENN ANX E, PA 19106 US</a></li>
<li class="ui-menu-item" role="presentation"><a id="ui-id-89" class="ui-corner-all" tabindex="-1">WILLIAM PENN ANNEX E, PA 19106 US</a></li>
<li class="ui-menu-item" role="presentation"><a id="ui-id-90" class="ui-corner-all" tabindex="-1">PHILADELPHIA, PA 19106 US</a></li>
</ul>

Which looks like this: enter image description here

2 Answers 2

1

CSS selector:

Without more HTML or the URL to go on, you can select those items with a CSS selector (patterns used to select element(s)).

.ui-menu-item[role="presentation"]

The . , in the above selector, is the class selector i.e. selecting elements by className. This is hopefully specific enough as I also specify that the elements with className ui-menu-item should contain the text role="presentation".

A more general approach might be ieDoc.getElementsByClassName("ui-menu-item").


CSS query results on HTML sample:

CSS query

The query shows that a list of elements are returned, 0-3, which will require the .querySelectorAll method of the HTML element (ieDoc variable) to capture all the matching items and return a nodeList which can then be iterated over.


VBA:

Dim NodeList As Object, i As Long
Set NodeList = ieDoc.querySelectorAll(".ui-menu-item[role=""presentation""]")

For i = 0 To NodeList.Length - 1
    Debug.Print NodeList.item(i).Click '<==this way          '
   'Debug.Print NodeList(i).Click   '<==Or this method
Next i

You may additionally need to set focus first with e.g. NodeList.item(i).focus ; assuming method supported.


More info:

See my answer here.

Sign up to request clarification or add additional context in comments.

Comments

0

Hello you can try to select it manualy and then look if the URL has changed. If yes, then you can simply navigate to this URL and then all things will be selected. Can you send me the website URL?

Best Regards

Udar

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.