提示对象不支持他的属性或方法



在选择左侧按钮的 1 后,我正在尝试更新右侧字段的 1,但提示运行时错误 438 代码。

我尝试更改代码最后一行的元素和属性,但似乎没有任何效果。

下面是我的 VBA 脚本的一部分:

Sub BrowseToWebTest1()
Dim ie As Object
Dim the_button_elements As Object
Dim button_element As Object
Dim radioButton As Object
Dim radioButtons As Object
Dim doc As HTMLDocument
Set ie = New InternetExplorerMedium
ie.navigate "company system web"
ie.Visible = True
While ie.Busy
DoEvents
Wend
Set doc = ie.document
Set the_button_elements = doc.getElementsByTagName("button")
For Each button_element In the_button_elements
    If button_element.getAttribute("onclick") = "CreateAcqCase();" Then
        button_element.Click
        Exit For
    End If
Next button_element
Call doc.getElementByName(“TransactionID”).setAttribute(“value”, “test”)

下面是 DOM 资源管理器代码:

<input name="$PAcqCaseCreation$pTransactionID" class="leftJustifyStyle" id="TransactionID" style="width: 175px;" type="text" maxlength="15" value="" data-ctl='["TextInput"]' minchars="15" validationtype="minchars" data-changed="false">

希望有人打电话帮助,以便我可以相应地更新字段。顺便说一下,我正在使用IE11和窗口10

1(你在这里有一个错误:

doc.getElementByName(“TransactionID”).setAttribute(“value”, “test”)

该方法getElementsByName,请注意表示复数的s - 返回集合。由于它是一个集合,因此需要提供适当的索引来定位感兴趣的元素。

2(此外,您还引入了智能"您想要的地方"。

3(既不需要call关键字,也不需要释义。

4( name属性为:

name="$PAcqCaseCreation$pTransactionID" 

id属性是:

id="TransactionID"

id可能是唯一的,并且是更好的选择器(并且是单数的,因此没有s或索引(:

doc.getElementId("TransactionID").setAttribute "value", "test"

否则

doc.getElementsByName("$PAcqCaseCreation$pTransactionID")(0).setAttribute "value", "test" 

这将假设集合中的第一个元素是正确的;否则,更改索引。

5( 您可以替换所有这些(并删除关联的声明(:

Set the_button_elements = doc.getElementsByTagName("button")
For Each button_element In the_button_elements
    If button_element.getAttribute("onclick") = "CreateAcqCase();" Then
        button_element.Click
        Exit For
    End If
Next button_element

用一行:

doc.querySelector("[onclick='CreateAcqCase();']").Click

最新更新