0

I tried several different methods to select a radio button or click on the image. There is an onclick task that is to be triggered. I can't automate any further until this opens up.

Sub AirCan()
    Dim HTMLInput As MSHTML.IHTMLElement
    Dim HTMLButtons As MSHTML.IHTMLElementCollection
    Dim HTMLButton As MSHTML.IHTMLElement
    Dim doc As MSHTML.HTMLDocument
    Dim img As MSHTML.HTMLImg
    On Error GoTo Err_Clear
    MyURL = "https://XXXXXXXXXX.com/en/XXXXXXXXXXXXX"
    Set MyBrowser = New InternetExplorer
    MyBrowser.Silent = True
    MyBrowser.navigate MyURL
    MyBrowser.Visible = True
    Do
    Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
    Set HTMLDoc = MyBrowser.document
    HTMLDoc.all.paymentAmount.Value = "111" 'Enter your email id here
    HTMLDoc.all.groupPayment.click
    Do While MyBrowser.readyState <> READYSTATE_COMPLETE
        DoEvents 
    Loop 

    Set allInputs = HTMLDoc.getElementsByTagName("img")
    For Each element In allInputs
        If element.getAttribute("src") = "/HPPDP/hpp/images/ca_visa.png" Then
            element.click
            Exit For
        End If
    Next
    Err_Clear:
    If Err <> 0 Then
        Err.Clear
        Resume Next
    End If
End Sub

CODE from the website, clicking the radio button or any of the 3 images will do what I need,

  • It's hard to tell when scraping websites. Are you sure the desired action is triggered by clicking on the .png image and not a DIV or some other object on the web page? – Jody Highroller Oct 01 '21 at 01:09
  • If the link has a `onclick` function then try `execScript` the function (see this [answer](https://stackoverflow.com/questions/31521205/how-to-find-and-call-javascript-method-from-vba)) Without access to the URL and/or snippet of the relevant HTML code, it's hard to help you. – Raymond Wu Oct 01 '21 at 04:25

0 Answers0