VBA getElementById doesn't work for button

ε祈祈猫儿з 提交于 2019-12-11 03:08:00

问题


I am trying to go on a website, type a value in a textbox and then click the searchbutton to search for my value. My Problem is, that i can't get the button element, to fire the click event.

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>

the secont getElement call is supposed to get the button, the object is null though. Does anyone know where i did a mistake?


回答1:


Replace:

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

with:

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

You need to look for the element by the Name not the Id




回答2:


You are using getElementById, which looks for the id of an element.

Your input button does not have any id attribute set, and this is why you cannot find it.

Add a value for the id attribute as so, and you will see it working:

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

Then:

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


来源:https://stackoverflow.com/questions/31201788/vba-getelementbyid-doesnt-work-for-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!