Excel VBA为IE页面上的输入框添加值

问题描述 投票:0回答:1

第一次尝试这个。

我在网页上有以下HTML,我正在使用ExcelVBA来抓取数据。

<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>

如何定位input role="combobox",因为它没有id或class。使用jQuery,我会在div class="program-filters"中找到这个输入。

谢谢

html excel vba
1个回答
1
投票

假设您已经有一个HTML文档可以使用,您可以这样做:

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

如果它始终是此页面上的第一个输入框,它将起作用。单击按钮以提交以这种方式填充的输入框有时需要更改输入框的类,以模拟手动填充此字段时发生的更改,否则JS验证将认为该字段为空。

© www.soinside.com 2019 - 2024. All rights reserved.