Selecting 1st element out of 32

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Selecting 1st element out of 32

Post by omayer » Thu Feb 07, 2013 8:06 am

there are 32 elements match the RanoreXPath, how do I select 1st element out of 32 elements, thank you in advance

//cell[@columnindex='2']/text[@id='lblLocation' and @caption='Auroa, MN']
Tipu

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

Re: Selecting 1st element out of 32

Post by Support Team » Thu Feb 07, 2013 5:48 pm

Hello,

The following RxPath should select the first element:

Code: Select all

//cell[@columnindex='2']/text[@id='lblLocation' and @caption='Auroa, MN' and first()='True']
Please take a look at RanoreXPath in our User Guide for more information.

Regards,
Markus (T)

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Selecting 1st element out of 32

Post by omayer » Thu Feb 07, 2013 6:44 pm

Thank you Markus. :D
Tipu

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

Re: Selecting 1st element out of 32

Post by Support Team » Thu Feb 07, 2013 8:10 pm

Just a follow-up on that topic, since I expect the obvious question to come up shortly: How to select the second, third, ... Xth element? :D

When you use "FindSingle" or the repository, Ranorex will always get the first element of all elements found for a RanoreXPath. If you want the Xth element, just use an additional index "[X]". The following example selects the 5th element:

Code: Select all

//cell[@columnindex='2']/text[@id='lblLocation' and @caption='Auroa, MN'][5]
Regards,
Alex
Ranorex Team

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Selecting 1st element out of 32

Post by omayer » Fri Feb 08, 2013 5:13 pm

Thank you Alex, this is Great.
Tipu

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

Re: Selecting 1st element out of 32

Post by Support Team » Fri Feb 08, 2013 5:32 pm

You are welcome! :D

Regards,
Alex

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Selecting 1st element out of 32

Post by omayer » Fri Feb 08, 2013 6:05 pm

My mistake, it was not clickable after finding the 1st element, I do need to click on 'btnCan' After finding the 1st element(Saukaripds, MN) out of 32 element

//row[@index='3']/cell/table/row/cell[@text='xyz ']/button[@id='btnCan']
this button resides on previous cell of the 1st Element that found
Thank you.
You do not have the required permissions to view the files attached to this post.
Tipu

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

Re: Selecting 1st element out of 32

Post by Support Team » Fri Feb 08, 2013 6:25 pm

I guess you'll need a RanoreXPath that retrieves you the sibling cell. The following documentation and resources should help you in finding the correct RanoreXPath:
http://www.ranorex.com/forum/how-do-i-g ... html#p6326
http://www.ranorex.com/support/screencasts.html#c2669
http://www.ranorex.com/support/user-gui ... html#c3296

Regards,
Alex
Ranorex Team

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Selecting 1st element out of 32

Post by omayer » Fri Feb 08, 2013 9:27 pm

Thank you Alex, Here is the code that working for me

Code: Select all


                SmartSearchPage.ClickOnCellButton(smartSearch.FindSingle(".//cell[@columnindex='2']/text[@id='lblLocation' and @caption='"+firstCityAndState+"'and first()='True']"));

#region| After matching the search result in Second Column(Eden, MN), then Click on Name at 1st Column 
		public static void ClickOnCellButton(Ranorex.FlexElement text)
		{

			string rxPath = text.GetPath().ToString();
		
			Unknown newRxPath = rxPath.Replace("/cell[@columnindex='2']/text[@id='lblLocation']", "/cell[@columnindex='1']");

			newRxPath.Click();
			
	
		 }
		#endregion
Tipu

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

Re: Selecting 1st element out of 32

Post by Support Team » Mon Feb 11, 2013 9:52 am

A small follow-up on that topic: You could also use the ".." parent operator and the "preceding-sibling" axis to achieve the same result:

Code: Select all

//cell[@columnindex='2']/text[@id='lblLocation' and @caption='Auroa, MN'][5]/../preceding-sibling::cell
Regards,
Alex
Ranorex Team