Hack Forums
[.NET] Object reference null on webbrowser's radio button - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Object reference null on webbrowser's radio button (/showthread.php?tid=6007528)



Object reference null on webbrowser's radio button - Shadow Reign - Sep 13, 2019

I am attempting to select a radial button on a webpage through webbrowser using

Code
       Dim checkB As HtmlElement

       checkB = WebBrowser1.Document.GetElementById("offerListInput_-1595316507")

       checkB.SetAttribute("checked", True)

however I keep getting object reference null and I cannot figure out why. The only thing I can figure is maybe the website isn't loaded when it does this, and if so, how can I tell it to load the page before it occurs? I already have another one using

Code
Public Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

to tell me when the page is loaded so it can press a button, and i've tried doing it again but it will not allow it. I've also tried using a goto statement but it will not recognize it in another sub.


I'm stuck, can anyone assist me?

Basically i'm trying to load a webpage, check if it's loaded, press a button, check if it's loaded, select a radial option, see if it's loaded, and then input more data.


RE: Object reference null on webbrowser's radio button - riu41776 - Sep 13, 2019

It means that checkB is null, because the specified element couldn't be found.

So when you try to access checkB, you get the exception because, it is, null.

Consider using an organized package like HtmlAgilityPack.


RE: Object reference null on webbrowser's radio button - Shadow Reign - Sep 13, 2019

I'm not sure why it would be null, that's what the elementID is called so i'm confused


RE: Object reference null on webbrowser's radio button - Claw - Sep 15, 2019

Make sure the element id is correct, also check if the element accept true and false or have dedicated type.