VBA代码用于在没有ID的文件中填充数据?

时间:2018-07-06 17:23:36

标签: html vba

我尝试将数据填写到网站字段中, 我可以填写前4个,但第5个不起作用, 我试图getelementsbyName,ClassName,但仍然无法正常工作, 有人可以帮忙吗? 这是我使用的代码:

With ie.document
    .all.Item("first_name").Value = "FirstName"
    .all.Item("last_name").Value = "Lastname"
   .all.Item("email_address").Value = "Email@email.com"
    .all.Item("phone").Value = "201-222-1111"
    .all.Item("dba_name").Value = "business name"
End With

这是HTML。

<div class="formbox">
    <div class="padding">
      <div class="inside">
          <div id="formfield">
      <!--<p>Click Here For Help
      <img src="/images/helpbutton.jpg">
      </p> -->

    <input type="hidden" name="username" value="">
    <input type="hidden" name="password" value="">
    <input type="hidden" name="isTsys" value="" /> 

    <span id = "partner_name" style = "display:none">HAPPY TEAM</span>



        <div style="position:relative;width:600px;margin-left:2em;">
        <div style="margin-bottom:1em;width:90%;font-size:14px;border-bottom:1px solid #d3dde3;color:#3d7499;font-weight:bold;">Partner Name</div>
        <p>HAPPY TEAM</p>
    <div style="margin-bottom:1em;width:90%;font-size:14px;border-bottom:1px solid #d3dde3;color:#3d7499;font-weight:bold;">Contact</div>
        <p>
        <label>* First Name</label>
        <input type="text" name="first_name" value="" class="form_input"  />
        </p>
        <p><label>* Last Name</label>
            <input type="text" name="last_name" value="" class="form_input"  />
      </span>
        </p>
        <p><label>Email Address</label>
        <input type="text" name="email_address" value="" class="form_input field_input"  />
        </p>
         <p><label>* Phone</label>
         <input type="text" name="phone" value="" class="form_input" maxlength="15" 0="" 1="onKeyUp="autotab(this,'dba_name')""  />        </p>
        <div style="margin-bottom:1em;width:90%;font-size:14px;border-bottom:1px solid #d3dde3;color:#3d7499;font-weight:bold;">Company</div>
         <p><label><a href="javascript:void(0)" class="popup" name="dba_name" tabindex="-1">* DBA Name/Trading Name</a></label>
        <input type="text" name="dba_name" value="" class="form_input field_input"  />        </p>
           <p><label>Address</label>
        <input type="text" name="dba_address" value="" class="form_input field_input"  />        </p>

        <p><label>City</label>
        <input type="text" name="dba_city" value="" class="form_input field_input"  />        </p>
        <p><label>State/Province</label>
          <input style="margin-top: .3em; border: 2px solid #70AAD1; font-size: 15px; padding: 4px 10px;" class="state_province" name="dba_state" id="state">

        </p>

1 个答案:

答案 0 :(得分:0)

使用

.querySelector("a[name=dba_name]").Value = "business name"

所以

With ie.document

 .querySelector("a[name=dba_name]").Value = "business name"

可能失败,

 .querySelector("a[name=dba_name]").innerText = "business name"

以下a[name=dba_name]是CSS选择器。它通过样式来定位元素。该选择器以具有属性a的{​​{1}}标签和值为name的元素为目标。当我使用dba_name方法应用选择器时,只会检索到第一个匹配项。