GetValue when Element Tag could change

Ask general questions here.
keenon
Posts: 14
Joined: Fri May 22, 2015 9:48 pm

GetValue when Element Tag could change

Post by keenon » Mon Sep 14, 2015 7:29 pm

Hi All,

I am running into an issue trying to getvalue of a specific element. The element has the chance to either be innerText or TagValue depending upon how the number is stored. I would like to create a method to first check what tag the number is stored in and then get that value based on that tag. I thought this could be done using an if statement to check if either tagvalue or innertext is null or if either exists, but I am striking out. Any thoughts?

Thanks,
Keenan

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

Re: GetValue when Element Tag could change

Post by odklizec » Wed Sep 16, 2015 8:12 am

Hi Keenon,

You can try for example this code:
public void CheckRepoItemValue(Ranorex.Adapter repoItem)        	
        {
        	Ranorex.WebElement repoItemWebElement = repoItem.Element;
        	if (repoItemWebElement.TagValue!=null & repoItemWebElement.InnerText!=null)
        	{
				// both TagValue and InnerText is not null
				// do whatever you want
        	}
        	else if (repoItemWebElement.InnerText!=null)
        	{
				// InnerText is not null
				// do whatever you want
        	}
        	else if (repoItemWebElement.TagValue!=null)
        	{
				// TagValue is not null
				// do whatever you want  		
        	}
        	else
        	{
        		// both InnerText and TagValue is null
			// do whatever you want     		
        	}
        }
You can simply add a new UserCode action (with the above code) to recording of your choice, then assign a repository item to the UserCode parameter repoItem.

Hope this helps?
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

keenon
Posts: 14
Joined: Fri May 22, 2015 9:48 pm

Re: GetValue when Element Tag could change

Post by keenon » Wed Sep 16, 2015 9:58 pm

Thank you so much Pavel. This is exactly what I needed. I also found that before reaching the element during navigation, there is a clear indication that the tag will be innertext or tagvalue so I figure there are also other ways to write this as well, but I will be using what you mentioned. I appreciate you spending the time to help.

Thanks,
Keenan

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

Re: GetValue when Element Tag could change

Post by odklizec » Thu Sep 17, 2015 8:00 am

Hi Keenan,

You are welcome. I'm glad I could help ;)
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