0

I'm doing a simply program to collect some e-mail's information from a "Disposable E-mail" (www.yopmail.com) page, when i try to press the "button" to open the e-mail using the functions GetElementById and InvokeMember, it doesn't works, the program says that GetElementById returns Nothing and the program stops.

I've tried in another pages using GetElementById and InvokeMember("click") and it works but, i am not sure why doesn't work in this case

When i inspect the element, it shows the next:

<div class="m" onclick="g(2,0);" id="m2"><div class="um"><a class="lm" href="m.php?b=hello&amp;id=me_ZGxkZQNkZGt1ZQH4ZQNkZQN5ZGN5ZN=="><span class="lmfd"><span class="lmh">13:50</span><span class="lmf">[SPAM]PINTRILL</span></span><span class="lms">PT | Snoopy &amp; Friends are Back.</span></a></div></div>

    wb.ScriptErrorsSuppressed = True

    wb.Navigate("www.yopmail.com?hello")

    wait(5)

    While fullyLoaded = False

        If wb.Url.Host <> "www.yopmail.com?hello" Then
            MsgBox("Yopmail 'finished' loading")
            wait(2)
            fullyLoaded = True
        Else
            MsgBox("inside while")
            wait(5)
        End If
    End While  
    wb.Document.GetElementById("m2").InvokeMember("click")

When the program stops, it shows me this:

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

System.Windows.Forms.HtmlDocument.GetElementById(...) gave back Nothing.

  • By navigating to element in other ways, and we can't tell you exactly how without whole html. – CruleD Oct 01 '19 at 20:55
  • body's full html? – Andrés González Oct 01 '19 at 21:47
  • What are these `wait(N)` things? Use the [DocumentCompleted](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser.documentcompleted) event, also checking whether the [WebBrowser.ReadyState = WebBrowserReadyState.Complete](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser.readystate) before parsing HtmlElements. Also, read the notes here: [How to get an HtmlElement value inside Frames/IFrames?](https://stackoverflow.com/a/53218064/7444103) – Jimi Oct 01 '19 at 22:40
  • `wait(N)` is a method that wait for `N` seconds, that lets me wait before execute the next part of code... And i don´t use the `DocumentCompleted` because i create the object `wb` in the code, `Dim wb As New WebBrowser` so when i try to do the method `wb_DocumentCompleted` its make me and Error whit the `Handles`, say something like the `Handles` should have a `WithEvent` object. I tried doing the comparasion `WebBrowser.ReadyState = WebBrowserReadyState.Complete` but it doesn´t work apparently. – Andrés González Oct 01 '19 at 23:07
  • You need to use the [AddHandler](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/addhandler-statement) statement to create an event handler at run-time. The `WebBrowser.ReadyState` property (to use inside the `DocumentCompleted` handler) works well, if you follow the notes in the link I posted. The way you're trying to wait for the HTML document to complete will only cause trouble (a lot of trouble). – Jimi Oct 01 '19 at 23:30
  • I am reading all the links that you posted, are very useful because i don't know so much about VB, i will finish to read them and re-write the parts that don't work and cause troubles... If i have any problem, i will add it like an edit. – Andrés González Oct 01 '19 at 23:39
  • Check out the code [here](https://stackoverflow.com/a/54030367/7444103), it's more or less what you need to do. – Jimi Oct 02 '19 at 00:16

0 Answers0