Page 1 of 1

GetValue when Element Tag could change

Posted: Mon Sep 14, 2015 7:29 pm
by keenon
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

Re: GetValue when Element Tag could change

Posted: Wed Sep 16, 2015 8:12 am
by odklizec
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?

Re: GetValue when Element Tag could change

Posted: Wed Sep 16, 2015 9:58 pm
by keenon
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

Re: GetValue when Element Tag could change

Posted: Thu Sep 17, 2015 8:00 am
by odklizec
Hi Keenan,

You are welcome. I'm glad I could help ;)