Use VBA code to click on a button on webpage

前端 未结 2 1463
悲&欢浪女
悲&欢浪女 2020-12-11 09:48

I am editing a vba program and want to code the vba to click on a button in a webpage. The html for the button is:



        
相关标签:
2条回答
  • 2020-12-11 10:43

    Is there a reason you couldn't give the element an id?

    i.e.:

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

    then:

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

    edit: Based on your comment, you'd have to grab all input elements on the page, and then cycle through them looking for the one that makes your input unique:

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

    Something along those lines anyway

    0 讨论(0)
  • 2020-12-11 10:48

    Perhaps something on the lines of:

    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.

    0 讨论(0)
提交回复
热议问题