【问题标题】:VBA - Checking Checkbox in IEVBA - 在 IE 中检查复选框
【发布时间】:2017-06-26 19:24:45
【问题描述】:

我正在尝试检查网站上的复选框。

复选框 HTML:

<input name="ApplicationSearchGroupsSelect_0" title='Select "Basic Access - Computer Logon"' type="checkbox" value="1">

复选框上方的 HTML:

<form name="main" id="main" onkeypress="return imOnKeyPress(event)" action="?facesViewId=/app/page/screen/standard_search.jsp" method="post">

代码

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

当我尝试运行此代码时没有任何反应(没有错误消息,代码完成运行并且没有检查任何内容)。除了触发 javascript 事件之外,尝试单击按钮,选中复选框,使 selected=true,我不知道如何单击此复选框,并且数小时的网络搜索没有返回任何内容。我也尝试将值更改为 0,1,2,但没有任何反应。

关于如何检查我尝试过的复选框之外的任何想法?谢谢!

【问题讨论】:

  • 我认为And ele.Title Like "Select "Basic Access - Computer Logon"" 甚至不会编译。字符串中的双引号需要通过将两个双引号放在一行中来进行转义,如下所示:And ele.Title Like "Select ""Basic Access - Computer Logon""" Then
  • 设置 objinputs = aExplorer.document.getElementsByTagName("input")

标签: html excel vba internet-explorer checkbox


【解决方案1】:

试试

aExplorer.document.forms("main").getElementsByName ("name=""ApplicationSearchGroupsSelect_0""")(0)

或者,

aExplorer.document.getElementsByTagName("form")(0).getElementsByName ("name=""ApplicationSearchGroupsSelect_0""")(0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    相关资源
    最近更新 更多