VBA html选项选择并输入

时间:2018-12-10 01:31:39

标签: html

我对使用VBA和html完全陌生,希望有人可以帮助我。

在我需要获取信息的网站上,有一个下拉列表和一个输入框,该框根据下拉列表中选择的选项而变化。

使用VBA,我可以更改下拉列表选项,但输入框不会更改,它与默认选项相同。

这是我正在运行的代码

Dim ie As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HMTLInputs As MSHTML.IHTMLElementCollection
Dim HTMLInput As MSHTML.IHTMLElement

ie.Visible = True
ie.navigate "myURL"

Do While ie.readyState <> READYSTATE_COMPLETE
Loop

Set HTMLDoc = ie.document

HTMLDoc.getElementById("zkComp62").Click

HTMLDoc.getElementById("zkComp66").Click

Set seleccion = HTMLDoc.getElementById("zkComp118")
seleccion.selectedIndex = 3

这是我从网站上获得的hmtl代码

<table id="tblFiltros">  <tbody>
    <tr id="zkComp119">
      <td id="zkComp120">
        <span class="z-label" id="zkComp121">Buscar por:</span>
      </td>
      <td id="zkComp122"></td>
      <td id="zkComp123"></td>
      <td id="zkComp124">
        <select id="zkComp118" selectedindex="0">
          <option id="zkComp125" selected="selected">Fecha de activación</option>
          <option id="zkComp127">Cliente</option>
          <option id="zkComp129">No. de Cliente</option>
          <option id="zkComp131">Contrato</option>
          <option id="zkComp133">Estatus</option>
          <option id="zkComp135">Distribuidor</option>
         </select>
        </td>
        <td id="zkComp137">
          <span class="z-label" id="zkComp94">Inicio:</span>
          <i class="z-datebox" id="zkComp142">
            <input class="z-datebox-inp" id="zkComp142-real" type="text" size="11" value="" autocomplete="off">
            <i class="z-datebox-btn" id="zkComp142-btn"></i>
            <div id="zkComp142-pp" style="display: none;"></div>|           </i>
          <span class="z-label" id="zkComp143">Fin:</span>
          <i class="z-datebox" id="zkComp144">
            <input class="z-datebox-inp" id="zkComp144-real" type="text" size="11" value="" autocomplete="off">
            <i class="z-datebox-btn" id="zkComp144-btn"></i>
            <div id="zkComp144-pp" style="display: none;"></div>              </i>
         </td>
      </tr>
   </tbody>
</table>

但是,如果我在网站上手动单击所需的选项,则代码中的最后一个td会更改,看起来像这样

<table id="tblFiltros">
<tbody>
  <tr id="zkComp119">
    <td id="zkComp120">
      <span class="z-label" id="zkComp121">Buscar por:</span>
    </td>
    <td id="zkComp122"></td>
    <td id="zkComp123"></td>
    <td id="zkComp124">
      <select id="zkComp118" selectedindex="0">
        <option id="zkComp125" selected="selected">Fecha de activación</option>
        <option id="zkComp127">Cliente</option>
        <option id="zkComp129">No. de Cliente</option>
        <option id="zkComp131">Contrato</option>
        <option id="zkComp133">Estatus</option>
        <option id="zkComp135">Distribuidor</option>
       </select>
    </td>
    <td id="zkComp137"><input class="z-textbox" id="zkComp97" type="text" value=""></td></tr></tbody></table>

我已经查看了其他答案,但是找不到适合我的代码的内容。 我已经尝试使用FireEvent,但是我并没有进行任何更改,也没有使用getelementsbyID(“”)。focus进行任何更改。但是我仍然无法使其工作。

谢谢

0 个答案:

没有答案