Attribute null check

Ask general questions here.
kemal.hakan
Posts: 1
Joined: Wed Dec 11, 2019 12:57 pm

Attribute null check

Post by kemal.hakan » Wed Dec 11, 2019 1:07 pm

Hello ,

The below code have to continue even if attribute null.. But When I run code , it gives null exception. I can't use '?' after "GetAttributeValue("Text")"

LastElement = containerList[containerList.Count-1].Children[0].GetAttributeValue("Text") ;

What can I do ?

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

Re: Attribute null check

Post by odklizec » Thu Dec 12, 2019 1:13 pm

Hi,

Try to use Element.GetAttributeValueText instead of GetAttributeValue. And then use check like this:

Code: Select all

LastElement = containerList[containerList.Count-1].Children[0].Element.GetAttributeValueText("Text") ;
if (LastElement == null)
{
    LastElement = "";
}
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