当 Excel VBA 说它不可见但实际上可见时,有没有办法点击单选按钮?

Is there a way to click on a radio button when Excel VBA says its not visible but it is actually visible?

如何在表单中单击网页上的单选按钮?我正在尝试编写一个代码来自动填写 Excel VBA 的表单。 这是问题陈述:需要单击页面上的三个选项之一“https://moverguide.usps.com/mgo/disclaimer" or https://moversguide.usps.com/mgo-m/disclaimer 即“个人”、“家庭”和“企业”,我得到以下错误:

Run time error 11: NoSuchElementErrorElement Cannot click on element

当我使用这个示例代码时:

If var = individual or family or business Then
        If obj.FindElementById("move-type-var").IsPresent Then
            obj.FindElementById("move-type-var").Click
        End If

或此错误:

Runtime error 7

NoSuchElementError

当我运行下面的示例代码:

if condition satisfied then
                obj.FindElementByCss ("css=.row--reskin:nth-child(1) .reskin__card:nth-child(1) > .reskin__card--label)")

            End If

我通过从 Firefox 中提取 css 目标获得了 css 参数。基本上,我使用 Selenium IDE 记录了一个脚本来查看究竟发生了什么,以便我为我的 Excel VBA 解决方案利用适当的目标值。

当我手动检查源代码时,IE 控制台 (F12) 中的一个属性“aria-checked”设置为 checked/true。当我自己单击其中一个选项时,就会发生这种情况。这是我必须在代码中启用的吗?

只是一个免责声明:总体上 Excel VBA 很好,但探索网络表单并且对这方面很陌生。

工具:用于 IE11 的 Selenium webdriver,MS Excel (office 365),VBA

它们是标签而不是单选按钮。您可以使用 css attribute = value 选择器进行定位;将感兴趣的选项字符串连接到 for 属性值中。我使用略有不同的开始 url 来避免不必要的步骤。

Dim var As String

'individual, family, business
var = "business"

obj.findElementByCss("[for='move-type-" & var & "']").Click