Excel VBA how to click on onclick div event on IE11

I have searched and searched but did not find a solution to solve this problem,

How do I fire an onclick event that is in a div? I am getting everything right by testing it with its name and getattribute, but it just won't click.

IE.document.getElementById("btn_header").FireEvent ("onclick")
IE.document.getElementById("btn_header").click
IE.document.getElementById("btn_header").parentElement.click

      

Web code

<td>
    <div id='btn_header' title='BTN' onclick="window.open('http://www.google.com','_blank');"></div>
</td>

      

I also noticed that some site says Fireevent doesn't work with IE11 for some reason, are there any other alternatives?

+3


source to share


3 answers


div.FireEvent "onclick"

should work (in the following example tested with IE11). Maybe your div is empty (contains nothing to click on?).

HTML used to validate the code here .




' Add reference to Microsoft Internet Controls (SHDocVw)
' Add reference to Microsoft HTML Object Library

Sub TriggerDivClick()
    Dim ie As SHDocVw.InternetExplorer
    Dim doc As MSHTML.HTMLDocument
    Dim div As HTMLDivElement
    Dim url As String

    url = "file:///c:/temp/divOnClick.html"
    Set ie = New SHDocVw.InternetExplorer

    ie.Visible = True
    ie.navigate url

    While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
        DoEvents
    Wend

    Set doc = ie.document
    Set div = ie.document.getElementById("btn_header")

    div.FireEvent "onclick"
    ie.Quit

    Set ie = Nothing
End Sub

      

+1


source


You can also try calling the script directly:



IE.document.parentWindow.execScript "window.open('http://www.google.com','_blank');", "javascript"

      

+1


source


This article helped me a lot, I used a direct script method call and it works fine. I used it, when I click one button and then call the script, it loads the text into another button.

I would like to have any method or example or YouTube to delete a web page with data in an iframe using Excel VBA

Deepak

0


source







All Articles