我在网页中有两个三个下拉菜单。手动将第一个下拉列表选择为“否”时,其他两个下拉列表会自动显示零。点击进入时,它将移至下一个html页面。但是,我可以使用vba在所有三个下拉列表中选择值,但在点击输入后,再次显示两个下拉列表,请显示“选择”而不是0,并且不会移至下一页。
我尝试了每个循环以及getElementByID
点击Enter后,网页应移至另一页。
<select name="UnhedgedYes" id="DDLLUnhedgedYes" style="font-size: 12px;"><option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="UnhedgedYes"></span>
<select name="DDLIPRUFCE" class="DDLIPRUFCE" id="DDLIPRUFCE" style="font-size: 12px;" data-val-required="Please Select Incremental Provisioning Requirement-due to UFCE" data-val="true" data-val-number="The field DDLIPRUFCE must be a number."><option value="">[Select]</option>
<option value="1" text="0">0</option><option value="6" text="10">10</option>
<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="DDLIPRUFCE"></span>
<input name="hidDDLIPRUFCE" id="hidDDLIPRUFCE" type="hidden" value="" autocomplete="off" data-val-required="The hidDDLIPRUFCE field is required." data-val="true" data-val-number="The field hidDDLIPRUFCE must be a number.">
<select name="DDLIRiskW" class="DDLIRiskW" id="DDLIRiskW" style="font-size: 12px;" data-val-required="Please Select Incremental Risk Weight- due to UFCE" data-val="true" data-val-number="The field DDLIRiskW must be a number."><option value="">[Select]</option>
<option value="2" text="0">0</option><option value="1" text="25">25</option></select>
<span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="DDLIRiskW"></span>
<input name="hidDDLIRiskW" id="hidDDLIRiskW" type="hidden" value="" autocomplete="off" data-val-required="The hidDDLIRiskW field is required." data-val="true" data-val-number="The field hidDDLIRiskW must be a number.">
下面是我尝试过的代码,但是它们不起作用。
1
ie.document.querySelector("option[value=No]").Selected = True
2
Set oSelect = ie.document.getElementById("DDLLUnhedgedYes")
oSelect.selectedIndex = 1
oSelect.FireEvent "onchange" ' although there is no fireevent exist on this element.
3
For Each op In ie.document.querySelectorAll("option")
If op.innerText = 0 Then
op.Selected = True
t = t + 1
If t = 2 Then
Exit For
End If
End If
Next
4此代码将在第一个下拉列表中输入No,在其他两个下拉列表中输入0,将禁用其他两个下拉列表。但是点击时仍然在同一页面上 而是在其他两个下拉列表中显示[选择]
Set Post = ie.document.getElementById("DDLLUnhedgedYes")
''I didn't use any index to do the job
For Each elem In Post.getElementsByTagName("option")
If InStr(elem.Value, "No") > 0 Then
elem.Selected = True
ie.document.getElementById("DDLIPRUFCE").getElementsByTagName("option")(1).Selected = True: ie.document.getElementById("DDLIPRUFCE").FireEvent ("onchange")
ie.document.getElementById("DDLIPRUFCE").disabled = True
ie.document.getElementById("DDLIRiskW").getElementsByTagName("option")(1).Selected = True: ie.document.getElementById("DDLIRiskW").FireEvent ("onchange")
ie.document.getElementById("DDLIRiskW").disabled = True
Exit For
End If
Next elem
ie.document.getElementById("btnEnter").Click