0

I need to capture the attributes of clicked elements in my application IE browser. All works fine and I am able to capture the attributes but the IE window gets unresponsive. i.e. if I click in the textbox the cursor will not be shown and mouse scroll will not work.

Imports System.Runtime.InteropServices
Imports mshtml
Public Class Form1
    Dim WithEvents IE As New SHDocVw.InternetExplorer()
    Dim WithEvents Doc As New mshtml.HTMLDocument
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Empty As Object = 0
        Dim URL As Object = "file://D:/AtestWeb/index_Calls_popup.htm"

        ' override BeforeNavigate2 event
        'IE.BeforeNavigate2 = New SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(AddressOf e1.OnBeforeNavigate2)

        IE.Visible = True
        IE.Navigate(URL)

        'IE.Navigate2(URL, Empty, Empty, Empty, Empty)

        System.Threading.Thread.Sleep(5000)
    End Sub
    Private Sub IE_DocumentComplete(ByVal pDisp As Object, ByRef URL As Object) Handles IE.DocumentComplete
        Doc = IE.Document
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CheckForIllegalCrossThreadCalls = False
    End Sub
    Private Sub Doc_onmouseup() Handles Doc.onmouseup
        ListBox1.Items.Add(Doc.activeElement.innerText)
    End Sub
End Class

If I remove mouse event everything works fine.

Thanks in advance for any help.

user1918906
  • 85
  • 1
  • 4
  • You can also use the standard WebBrowser control and do something like this: [Download Image under the Mouse pointer via WebBrowser](https://stackoverflow.com/a/56169490/7444103). Note that the clicked HtmlElement is determined using the `[WebBrowser].Document.GetElementFromPoint()` method. Then get the `[HtmlElement].InnerText` (or whatever). Also, read (in any case) the notes about the `DocumentComplete(d)` event and the IFrames part. – Jimi Jan 15 '20 at 18:37
  • 1
    `CheckForIllegalCrossThreadCalls = False` is **never** an acceptable way to deal with UI threading issues. – TnTinMn Jan 15 '20 at 20:17
  • Yes, this issue is not there when using WebBrowser. But I need to do this using IE since it's an upgrade from legacy application. – user1918906 Jan 16 '20 at 09:13

0 Answers0