问题
I'm attempting to check a checkbox on a website.
Checkbox HTML:
<input name="ApplicationSearchGroupsSelect_0" title='Select "Basic Access - Computer Logon"' type="checkbox" value="1">
HTML Above Checkbox:
<form name="main" id="main" onkeypress="return imOnKeyPress(event)" action="?facesViewId=/app/page/screen/standard_search.jsp" method="post">
Code:
Set objinputs = aExplorer.document.getElementsByTagName("form")
For Each ele In objinputs
If ele.Name Like "ApplicationSearchGroupsSelect_0" And ele.Title Like "Select "Basic Access - Computer Logon"" Then
ele.Focus
ele.Click
ele.Selected = True
ele.Checked = True
ele.FireEvent "onkeypress"
End If
Next
Do While aExplorer.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
aExplorer.document.getElementById("main").FireEvent ("onkeypress")
Do While aExplorer.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Nothing happens when I try to run this code (no error message, code completes running and nothing is checked). Beyond firing the javascript event, trying to click the button, check the checkbox, make selected=true, I don't know how to click this checkbox and hours of scouring the web hasn't returned anything. I've also tried changing the value to 0,1,2 and nothing occurs.
Any ideas on how to check a checkbox outside of what I've tried? Thanks!
回答1:
Try
aExplorer.document.forms("main").getElementsByName ("name=""ApplicationSearchGroupsSelect_0""")(0)
Or,
aExplorer.document.getElementsByTagName("form")(0).getElementsByName ("name=""ApplicationSearchGroupsSelect_0""")(0)
来源:https://stackoverflow.com/questions/42125623/vba-checking-checkbox-in-ie