0

I am trying to envoke a text url with no id, I am able to envoke it via the href.innertext just fine but for the program i am creating the innertext will not be completely known before hand. Therefore i am using keywords that i know will be included in the text.

I have tried to assign the href.innertext to a string and try "if string.contains("blah blah")" but i get an error.

        Dim HTML As HtmlDocument

        HTML = WebBrowser1.Document
        For Each href In HTML.Links
            item = href.innerText
            If item.Contains("Blah Blah") Then
                href.InvokeMember("click")
            End If
        Next

the code above returns

System.NullReferenceException: 'Object reference not set to an instance of an object.'

item was Nothing.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Brad
  • 33
  • 1
  • 5
  • That's not the way to work with the html document provided by a WebBrowser. Read the notes [here](https://stackoverflow.com/a/53218064/7444103) and use the `DocumentCompleted` event as described. – Jimi Sep 13 '19 at 07:38
  • Set a breakpoint on this code and when it hits use Debug > Windows > Threads. Verify it runs on the Main thread and is triggered by the DocumentCompleted event, it can't work correctly on a worker thread. It can also be caused by embedded Javascript altering the page content, nothing much you can about it but waiting long enough with a Timer until it is done. – Hans Passant Sep 13 '19 at 10:23

0 Answers0