Page 1 of 1

Object reference not set to an instance of an object

Posted: Thu Aug 27, 2015 2:46 pm
by Shahnaz
Hi..
I am using following code get value from UI " objName.Element.GetAttributeValue("Value").ToString=strTextValue " but it is giving run time error
"Object reference not set to an instance of an object" when the object value is blank in UI. But my requirement is to fetch even blank values..

Instead if i use " objName.Element.GetAttributeValue("Value")=strTextValue " it works but gives a warning "Implicit Conversion from Object to String"

Plz help to resolve this issue..

Re: Object reference not set to an instance of an object

Posted: Fri Aug 28, 2015 7:50 am
by odklizec
Hi,

It seems you forgot to add parentheses at the end of ToString method, so the code should be like this...
objName.Element.GetAttributeValue("Value").ToString()

Re: Object reference not set to an instance of an object

Posted: Fri Aug 28, 2015 10:34 am
by Shahnaz
Thanks for your reply.. I tried by adding .ToString() but still getting that error.. :(
I tried in this way Report.Log(ReportLevel.Info,repo.brsMediaView.objLabel.Element.GetAttributeValue("Value").ToString())

Re: Object reference not set to an instance of an object

Posted: Fri Aug 28, 2015 11:19 am
by odklizec
Are you sure the repo.brsMediaView.objLabel has "Value" attribute? Could you please upload the Ranorex snapshot of the element in question (repo.brsMediaView.objLabel)?

Re: Object reference not set to an instance of an object

Posted: Fri Aug 28, 2015 5:37 pm
by krstcs
Try changing "GetAttributeValue" to "GetAttributeValueText" and remove the ".ToString()" part.

Code: Select all

Report.Log(ReportLevel.Info,repo.brsMediaView.objLabel.Element.GetAttributeValueText("Value"));

Re: Object reference not set to an instance of an object

Posted: Mon Aug 31, 2015 11:28 am
by Shahnaz
@odklizec.. yes object has attribute "Value".. Solution provided by krstcs is working fine..
Thanks to both of you :) my problem is solved..