Retrieving Tagvalue from Repository Item with Variable

Class library usage, coding and language questions.
mcs
Posts: 29
Joined: Mon Aug 11, 2014 5:00 pm
Location: Portsmouth, NH

Retrieving Tagvalue from Repository Item with Variable

Post by mcs » Tue Jun 14, 2016 4:49 pm

Hi,
I am writing user code and, perhaps it's my level of C# coding knowledge that is causing me not to understand how to do the following:

I have a repo item named DateSelected with an xpath of /dom[@domain='10.1.0.50:90']/body[@tagvalue='']/div[1]/div[4]/div[1]/div[1]/div[@tagvalue='']/div[4]/form[@tagvalue='']/div[4]/?/?/table[@tagvalue='']/tbody/tr[1]/td[1]/table[@tagvalue='']//input[@tagvalue=$dateSelected]

This field is populated when a date in a calendar on the Webpage is selected. What I want to do is retrieve the text from this field and, eventually, validate that it matches the date selected in the calendar.

My issue is that, unless I have the tagvalue hard-coded rather than a variable, my code can't seem to find the field...

Any pointers will be greatly appreciated.
Thanks,
Mike

mcs
Posts: 29
Joined: Mon Aug 11, 2014 5:00 pm
Location: Portsmouth, NH

Re: Retrieving Tagvalue from Repository Item with Variable

Post by mcs » Tue Jun 14, 2016 8:08 pm

Some further information:
In addition to replacing the $dateSelected in my repo item with a value (other than the one I'm selecting in my test) and just '', I've tried the following three code items:

1. string dateSelected = repo.Webpage.PageSection.DateSelected_Txt.Element.GetAttributeValueText("tagvalue");

2. InputTag ITdateSelected = repo.Webpage.PageSection.DateSelected_TxtInfo.CreateAdapter<InputTag>(true);
string dateSelected = ITdateSelected.GetAttributeValue<InputTag>("tagvalue").ToString();

3. string dateSelected = repo.Webpage.PageSection.DateSelected_Txt.Element.GetAttributeValue("tagvalue").ToString();

None of this has resulted in my code finding the item...

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

Re: Retrieving Tagvalue from Repository Item with Variable

Post by odklizec » Wed Jun 15, 2016 8:11 am

Hi,

At first, could you please post a Ranorex snapshot (not screenshot!) of the problematic element?

At next, I think you are mixing few things ;) I suppose, that the tagvalue of given input changes with each selected date from calendar and that the calendar date changes every day you run the test? So basically, you cannot use hardcoded tagvalue for input in repository, because it would fail the next day, right?

What you need to do is to identify the input via another attribute and not the tagvalue (innertext/text) attribute, which is changing. If there is no other attribute you can use to identify that input, leave the xpath in repository without attributes. But make sure there is just one (correct) input found with such xpath! Otherwise, you will have to add the index after input attribute (like this: /table[@tagvalue='']//input[1]), where the index number should point to the correct input. Eventually, you can use relationship operators to identify the input.

BTW, the xpath you are using is not very good and very likely to fail in future, because of minimum of unique identification attributes and a lot of indexes. Such path is very fragile and not changes-proof. You should either try to find some unique attributes, use relationship operators, relative path operators and use indexes only if there is really no other way to identify the element. Please post the snapshot, so we can suggest you a better xpath that the one you are using now.
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

mcs
Posts: 29
Joined: Mon Aug 11, 2014 5:00 pm
Location: Portsmouth, NH

Re: Retrieving Tagvalue from Repository Item with Variable

Post by mcs » Wed Jun 15, 2016 4:12 pm

Thanks, Pavel.

Your answer pointed me in the right direction to solve this. I shortened my xpath and made the unique items tagname and id; I was then able to find the field in my code and retrieve the tagvalue. :D

Mike