Object reference not set to an instance of an object

Ask general questions here.
Shahnaz
Posts: 7
Joined: Thu Aug 27, 2015 2:25 pm

Object reference not set to an instance of an object

Post by Shahnaz » Thu Aug 27, 2015 2:46 pm

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..

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Aug 28, 2015 7:50 am

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()
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Shahnaz
Posts: 7
Joined: Thu Aug 27, 2015 2:25 pm

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

Post by Shahnaz » Fri Aug 28, 2015 10:34 am

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())

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Aug 28, 2015 11:19 am

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)?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Fri Aug 28, 2015 5:37 pm

Try changing "GetAttributeValue" to "GetAttributeValueText" and remove the ".ToString()" part.

Code: Select all

Report.Log(ReportLevel.Info,repo.brsMediaView.objLabel.Element.GetAttributeValueText("Value"));
Shortcuts usually aren't...

Shahnaz
Posts: 7
Joined: Thu Aug 27, 2015 2:25 pm

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

Post by Shahnaz » Mon Aug 31, 2015 11:28 am

@odklizec.. yes object has attribute "Value".. Solution provided by krstcs is working fine..
Thanks to both of you :) my problem is solved..