[RESOLVED]Object reference not set to an instance of an object.[Help]
Ok guys. Im trying to grab a HTML element style with my program, the problem is that when the page is loaded there is no style to that element, then if I click on that element and it has a style.
I have this
vb.net Code:
With WebBrowser1
If .Document.GetElementById("idSUOther9").Style is Nothing Then
.Document.GetElementById("i1668").InvokeMember("click")
End If
If .Document.GetElementById("idSUOther9").Style Is "display: none;" Then
.Document.GetElementById("i0116")
.Document.GetElementById("i0118")
End If
tLogin.Stop()
MessageBox.Show(.Document.GetElementById("idSUOther9").Style)
Return
then my program crashes here
vb.net Code:
If .Document.GetElementById("idSUOther9").Style is Nothing Then
.Document.GetElementById("i1668").InvokeMember("click")
End If
since idSUOther9 there is no style it cant grab its data. How can I check is "idSUOther9" has a style without crashing my program?
Thank you
Re: Object reference not set to an instance of an object.[Help]
I haven't played much with the WebBrowser control and HTML elements so I don't know the best practices with these but one way to solve your issue would be to handle the exception with a try/catch block. If the exception is caught then you know there is no style for "idSUOther9".
Re: Object reference not set to an instance of an object.[Help]
Does .Document.GetElementById("idSUOther9") return an object? If IT is producing Nothing, then the InvokeMember line will fail as well.
Basically, an "Object Reference not set to an instance of an object" is a pretty generic error. It's basically saying you're trying to do something to an object that doesn't exist; or use a method or function of an object that doesn't exist.
Re: Object reference not set to an instance of an object.[Help]
Quote:
Originally Posted by
Jenner
Does .Document.GetElementById("idSUOther9") return an object? If IT is producing Nothing, then the InvokeMember line will fail as well.
Basically, an "Object Reference not set to an instance of an object" is a pretty generic error. It's basically saying you're trying to do something to an object that doesn't exist; or use a method or function of an object that doesn't exist.
Yes. It suppose to return a value. but it crashes since idSUOther9 has to style yet.
Re: Object reference not set to an instance of an object.[Help]
What line crashes?
"It suppose to return a value." -- does that mean you don't know for sure that it does? That should be the first thing you should be checking. Try debugging... when it crashes, check the values of your objects... make sure they are what you expect them to be.
-tg
Re: Object reference not set to an instance of an object.[Help]
Quote:
Originally Posted by
techgnome
What line crashes?
"It suppose to return a value." -- does that mean you don't know for sure that it does? That should be the first thing you should be checking. Try debugging... when it crashes, check the values of your objects... make sure they are what you expect them to be.
-tg
It crashes here
vb.net Code:
If .Document.GetElementById("idSUOther9").Style is Nothing Then
because "idSUOther9" in this case doesn't have a style, so it cant grab its data.
Re: Object reference not set to an instance of an object.[Help]
so when you check: .Document.GetElementById("idSUOther9") .... you get "something"?
-tg
Re: Object reference not set to an instance of an object.[Help]
Yea, try:
Code:
If .Document.GetElementById("idSUOther9") IsNot Nothing AndAlso .Document.GetElementById("idSUOther9").Style is Nothing Then
...
Re: Object reference not set to an instance of an object.[Help]
Quote:
Originally Posted by
Jenner
Yea, try:
Code:
If .Document.GetElementById("idSUOther9") IsNot Nothing AndAlso .Document.GetElementById("idSUOther9").Style is Nothing Then
...
It works!
Thank you