VBA-在IE中选中复选框 [英] VBA - Checking Checkbox in IE

查看:170
本文介绍了VBA-在IE中选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm attempting to check a checkbox on a website.

复选框HTML:

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

HTML上方复选框:

HTML Above Checkbox:

<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,但什么也没发生。

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!

推荐答案

尝试

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

或者

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

这篇关于VBA-在IE中选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆