VBA getElementById 不适用于按钮

VBA getElementById doesn't work for button

我正在尝试访问一个网站,在文本框中键入一个值,然后单击搜索按钮来搜索我的值。 我的问题是,我无法获取按钮元素来触发点击事件。

VBA:

Dim i As Long
Dim objElement As Object
Dim objCollection As Object
 Dim result(2) As String
Dim timeout As Integer

Dim test As Object 'testweise

If IE Is Nothing = False Then
    IE.Quit
End If
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


Start:

' Send the form data To URL As POST binary request
IE.navigate "https://www.bundesanzeiger.de/ebanzwww/wexsservlet"

' Wait while IE loading...
Do While IE.Busy
    DoEvents
    Application.Wait DateAdd("s", 1, Now)
Loop
IE.Document.getElementbyid("genericsearch_param.fulltext").Value = "Mielke"
IE.Document.getElementbyid("(page.navid=to_quicksearchlist)").Click

HTML

<div class="bbg"><input name="(page.navid=to_quicksearchlist)" type="submit" alt="Suchen" value="Suchen"></div>

第二个 getElement 调用应该获取按钮,但该对象为空。 有谁知道我哪里做错了吗?

您正在使用 getElementById,它查找元素的 id

您的输入按钮没有设置任何 id 属性,这就是您找不到它的原因。

照这样为 id 属性添加一个值,您会看到它起作用了:

<input id="xyz" ... />

然后:

IE.Document.getElementbyid("xyz").Click

替换:

IE.Document.getElementbyid("(page.navid=to_quicksearchlist)").Click

与:

Set x = IE.Document.GetElementsByName("(page.navid=to_quicksearchlist)")
x(0).Click

您需要通过 Name 而不是 Id

查找元素