开发者

VB.NET GetElementById innertext

Okay so this is my html line with the ID:

<id="accounttype" class=inline-block"><strong><?=$_SESSION['accounttype']?></strong><br>
开发者_开发知识库

this is what it grabs

of course though that turns into text

<?=$_SESSION['accounttype']?>

this is my vb.net code

  TextBox4.Text = WebBrowser1.Document.GetElementById("accounttype").InnerText

When i run the program i get this error

Object reference not set to an instance of an object.


I don't see an element with an ID of accounttype. All I see is an element with an ID of newssite. GetElementById returns the element who has an attribute id equal to whatever you pass it. For example:

<div id="accounttype">Hello World</div>

And the VB.NET Code:

TextBox4.Text = WebBrowser1.Document.GetElementById("accounttype").InnerText

You may not have included the code; but you should also make sure the WebBrowser has completely loaded its contents before trying to work with it.


How to debug "Object reference not set to an instance of an object." errors

If you have a statement of type

A.B = C.D.E.F

then this error can occur if A is Nothing, if C is Nothing, if C.D is Nothing or C.D.E is Nothing.

So, to debug this error, split up your statement like this:

Dim d = C.D
Dim e = d.E
Dim f = e.F
A.B = f

Now the line in which the error occurs will tell you which object was Nothing. Then check the documentation of the method call that created this object to find out under which circumstances this method call returns Nothing.

If, after doing so, you still don't understand why this happens, return to StackOverflow and post a new question, adding the information you have gained (for example: Why does WebBrowser1.Document.GetElementById("accounttype") return Nothing even though there is an element with ID accounttype in my document?).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜