VBA填写网页文本框

时间:2014-08-18 09:36:30

标签: java vba

我正在尝试用getelementbyclassname()。值填充此文本框但它不起作用。它只适用于我使用innertext但这不是我想要的,因为它硬编码文本。我该如何处理这个元素,以便将文本传递给它?

<div class="form-field-bottom-field-css no-form-field-mandatory-sign-css">
<span dojoattachevent="onmouseover:onMouseOver, onclick:onClick, onmouseout:onMouseOut" class="freedom-base-mixin-css dijitValidationTextBox" widgetid="2a14bad3-825d-4956-8bf8-eda9a55104eaF_Age-widget">
    <input dojoattachpoint="textbox,focusNode,_aroundNode" dojoattachevent="onblur:onBlur,onfocus:onFocus,onkeyup:onKeyUp" id="2a14bad3-825d-4956-8bf8-eda9a55104eaF_Age-widget" name="" class="dijitReset dijitTextBox notDojoDndHandle" type="text" tabindex="0" aria-label="Number" value="" role="textbox" style="max-width: 7.5em; width: 90%;"><input type="hidden"><span dojoattachevent="onkeypress:onKeyPressIconNode,onkeyup:onKeyUpIconNode" dojoattachpoint="iconNode" class="notDojoDndHandle " style="vertical-align: middle; cursor: pointer; display: none;" tabindex="0" id="2a14bad3-825d-4956-8bf8-eda9a55104eaF_Age-widget-iconNode" aria-label="Number">
            <span class="a11y-text" style="cursor:pointer; display:none">&amp;</span></span>
    <div dojoattachpoint="invalidDiv" style="padding-top:2px;display:none;">
        <span class="invalidIcon"></span>
        <span dojoattachpoint="invalidSpan" role="alert" class="freedomInvalid lfFormFieldError"></span>
    </div>
</span>
</div>

VBA:

Dim IntExpl As Object
Set IntExpl = CreateObject("InternetExplorer.Application")
With IntExpl
      .navigate "URL"
      .Visible = True
      Do Until IntExpl.readyState = 4
Loop
.document.getElementsByClassName("lotusBtn")(0).Click
If Application.Wait(Now + TimeValue("0:00:5")) Then
.document.getElementsByClassName("form-field-bottom-field-css no-form-field-mandatory-sign-css")(0).Value = "1"
End If
End With
End Sub

2 个答案:

答案 0 :(得分:0)

发现它是如何工作的,我引用了错误的类 .document.getElementsByClassName(&#34; dijitReset dijitTextBox notDojoDndHandle&#34;)(0).innerText =&#34; 1&#34;

答案 1 :(得分:0)

For Each abc In IE.Document.getElementsByTagName("input")
    If abc.id="2a14bad3-825d-4956-8bf8-eda9a55104eaF_Age-widget" Then
        abc.value="YOUR VALUE"
  End If
Next

由于