Use the VBA code to click on the button on the web page.

I am editing a vba program and want to encode vba to click a button on a web page. Html button for button:

<input type="image" src="/lihtml/test_button3.gif" align="left" alt="File_Certificate_Go"/>

I assume that I would have to set the variable getElementBy ??? and then variable.click, but I can’t figure out exactly how to get the element (because it doesn’t have a name or id, and I can’t give it because it is not my web page).

Any help is much appreciated!

+3
source share
2 answers

Maybe something in the lines:

Set tags = wb.Document.GetElementsByTagname("Input")

For Each tagx In tags
    If tagx.alt = "File_Certificate_Go" Then
        tagx.Click
    End If
Next

Where wb is the WebBrowser control.

+3
source

Is there a reason you could not give the element an identifier?

i.e:.

<input id='myButton' type=image src="/lihtml/test_button3.gif" align=left alt=File_Certificate_Go> 

then

document.getElementById('myButton').click()

edit: , , , :

var elms = document.getElementsByTagName("input"); 
for (var i=0; i< elms.length; i++) 
    if(elms[i].src = '/lihtml/test_button3.gif') { elms[i].click(); }

-

+2

Source: https://habr.com/ru/post/1735281/


All Articles