有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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) 个答案

  1. # 1 楼答案

    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
    

    谢谢

  2. # 2 楼答案

    发现它是如何工作的,我引用了错误的类 文件getElementsByClassName(“dijitReset dijitTextBox notDojoDndHandle”)(0)。innerText=“1”