Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when I try to execute this code doc = appIE.document it is throwing error like comexception was unhandled...plz help me..
How to handle it



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim appIE As Object 'InternetExplorer
appIE = Nothing

Dim doc As HtmlDocument
'Dim appIE As Object = CreateObject("InternetExplorer.Application")
If appIE Is Nothing Then appIE = CreateObject("InternetExplorer.Application")
Dim URL = "https://www.facebook.com/souj.shanigaram/"
'Dim doc As HtmlDocument = appIE.document


With appIE
.Navigate(URL)
.Visible = True
End With

doc = appIE.document
For Each obj In doc.GetElementsByTagName("a")
If obj.innerText = "About" Then
obj.Click()
Exit For
End If
Next

What I have tried:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim appIE As Object 'InternetExplorer
    appIE = Nothing

    Dim doc As HtmlDocument
    'Dim appIE As Object = CreateObject("InternetExplorer.Application")
    If appIE Is Nothing Then appIE = CreateObject("InternetExplorer.Application")
    Dim URL = "https://www.facebook.com/souj.shanigaram/"
    'Dim doc As HtmlDocument = appIE.document


    With appIE
        .Navigate(URL)
        .Visible = True
    End With

    doc = appIE.document
    For Each obj In doc.GetElementsByTagName("a")
        If obj.innerText = "About" Then
            obj.Click()
            Exit For
        End If
    Next
Posted
Updated 12-Oct-17 6:34am

1 solution

The Navigate method[^] starts navigation to the specified page, and returns immediately. It does not wait for the navigation to complete.

You cannot access the document until the page has finished loading. You'll either need to wait for the NavigateComplete event[^] to fire, or wait for the Busy property[^] to return False.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900