使用VBA在IE中检查单选button,奇怪的行为

我遇到了一个让我难倒的问题。

我的问题如下:我想检查使用VBA的IE单选button。 应该很简单吧? 我检查了这个网站上的解决scheme,我尝试将它们应用于我的场景。 但是,似乎我甚至无法获得元素…

这是HTML源代码片段:

<table class="MainTable" width="962px"> <tr> <td class="HistorySections" style="height: 29px; vertical-align: top;"> <span id="lblReportType" class="Panel4" style="display:inline-block;height:15px;width:409px;"> Report Type</span> <table class="MainTable" width="413" style="height: 60px"> <tr> <td style="height: 22px"> <span style="display:inline-block;width:110px;"><input id="optRCV" type="radio" name="RptType" value="optRCV" onclick="javascript:setTimeout('__doPostBack(\'optRCV\',\'\')', 0)" /><label for="optRCV">Receivables</label></span> 

从我所能得到的,我的单选button被称为“optRCV”。

我尝试了各种方法来检查单选button,这取决于我在这里学到的东西,但总是失败。 在使用单选button的线路上出现“对象未设置”错误。 所以我试了一下简单的一行来看看有什么不对。

 MsgBox IE.document.getElementById("optRCV").ID 

从我对VBA和IE的有限的理解,这应该显示Radiobutton的ID,对吧? 我尝试了类似的东西,确保我正确使用它

 MsgBox IE.document.getElementsByTagName("TABLE")(0).ID 

此行显示一个带有ID的消息框(以及ID是空的,但不会导致错误)。

是否有任何理由,为什么我不能使用它的ID与单选button进行交互? 有趣的是,当我点击网页的顶部并使用查看源代码时,它会显示与当我单击单选button所在的网页部分时不同的源代码。

所以我的想法是,我首先需要告诉IE看在网页的正确部分,但我不知道如何做到这一点。

有什么想法吗?

 MsgBox IE.document.getElementsByTagName("TABLE")(0).ID 

你的代码返回表中包含span,td,tr等元素的集合,所以如果你想得到单选button,你不应该select第一个元素

你的代码应该是这样的:

 IE.document.getElementById("optRCV").getAttribute("id")