TheRealPapa
TheRealPapa

Reputation: 4539

Excel VBA add value to input box on IE page

First time trying this.

I have the following HTML in a web page and I am using Excel and VBA to scrape data.

<div class="program-filters">
   <span>Search for&nbsp;</span>
   <a>
      any gender&nbsp;<img src="/site/images/svg/DownArrow.svg" alt="Down Arrow" class="down-arrow-icon">
   </a>
   <span class="xs-hide">,</span>
   <br class="sm-hide md-hide lg-hide">
   <a>
      all ages&nbsp;<img src="/site/image/svg/DownArrow.svg" alt="Down Arrow" class="down-arrow-icon">
   </a>
   to
   <a>
      play&nbsp;<img src="/site/images/svg/DownArrow.svg" alt="Down Arrow" class="down-arrow-icon">
   </a>
   <br class="sm-hide md-hide lg-hide">&nbsp;near&nbsp;
   <div style="display: inline-block;">
    <input role="combobox" aria-autocomplete="list" autocomplete="off" value="SEARCH VALUE HERE">
   </div>
   <a class="in-map-btn btn btn-primary btn-go btn-mobile-fixed">GO</a>
</div>

How do I target the input role="combobox" as it has no id or class. With jQuery I would find this input inside div class="program-filters".

Thank you

Upvotes: 0

Views: 98

Answers (1)

Ryszard Jędraszyk
Ryszard Jędraszyk

Reputation: 2412

Assuming that you already have a HTML Document to work on, you can do it like this:

myHTMLDoc.GetElementsbyTagName("INPUT")(0).value = myValue

It would work if this is always the first input box on this page. Clicking on a button to submit input boxes filled this way sometimes requires to change class of the input box, to emulate change which happens when this field is filled manually, else JS verification will consider the field empty.

Upvotes: 1

Related Questions