How to get, update and use a repo items Xpath in user code

Class library usage, coding and language questions.
houseofcutler
Posts: 52
Joined: Fri Mar 21, 2014 4:22 pm

How to get, update and use a repo items Xpath in user code

Post by houseofcutler » Wed Jun 11, 2014 3:21 pm

Hi There,

I wanted to use an existing repository item path but then add to it to find a related element from which I could output a value (this will actually be used in validation later.

This is what I came up with and it works - It took me a little while to work it out (I'm still new). In the interest of improving my coding I am just wondering if there is a better/more efficient way than this
public void Get_Badge_Value()
        {
        	RxPath path = repo.ComGroupcallEmerge.ViewAnimator.Scroller.android_widget_LinearLayout.LinearLayout1.StudentDetails.Timetable.GetPath();
       	
            path = path +"/../../text[@rid='badge']";
        
            Text badge = Host.Local.FindSingle<Ranorex.Text>(path);
            
            string badgeNumber = badge.Element.GetAttributeValueText("Caption", new Regex("^([^a-zA-Z]*)"));
            Report.Info("User",badgeNumber);
 
        }
Many thanks

Ben

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to get, update and use a repo items Xpath in user code

Post by Support Team » Fri Jun 13, 2014 11:38 am

Hi Ben,

You could for instance also use the following approach to get the text element:
Ranorex.Text badge = repo.ComGroupcallEmerge.ViewAnimator.Scroller.android_widget_LinearLayout.LinearLayout1.StudentDetails.Timetable.FindSingle<Ranorex.Text>("./../../text[@rid='badge']");
//...
Regards,
Markus

houseofcutler
Posts: 52
Joined: Fri Mar 21, 2014 4:22 pm

Re: How to get, update and use a repo items Xpath in user code

Post by houseofcutler » Thu Jun 19, 2014 3:04 pm

Hi Markus,

That way is much better - thanks