Search for specific value in ANY cell in a table?

Ranorex Studio, Spy, Recorder, and Driver.
kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Search for specific value in ANY cell in a table?

Post by kmck » Wed Jul 24, 2013 10:02 pm

I've been trying to modify my RanoreXPaths to search for a specific value in any of the cells within a certain row of my table. I have tried

Code: Select all

/table/row/cell[@columindex="0"]
and

Code: Select all

/table/column[@index="0"]/cell
and

Code: Select all

/table/row/cell[1]
All of which shows all cells in my first row being highlighted while in Ranorex Spy. However, when I run my test, it short circuits at the first entry, and if the first entry does not equal the attribute text listed in the validation, then it fails.

For example, my first cell's data in my first row says "Steve", but I am looking for "Dan", who is in my first cell in my second row. Even though "Dan" is present, the validation stops at "Steve" in the first row and throws an error.

How do I get it to look at ALL the cells and verify my text exists in one of the cells within that specific column?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Search for specific value in ANY cell in a table?

Post by Ciege » Wed Jul 24, 2013 11:24 pm

1) Can you show your code you are using? Will help debug it...

2) You can just as easily get an IList of all cells in a row or table and loop that IList looking for that cell data.

Example of how to get all Cells from a Table the loop those cells:

Code: Select all

IList<Ranorex.Cell> AllCells = MyTable.FindDescendants<Ranorex.Cell>();
foreach (Ranorex.Cell ThisCell in AllCells )
{
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Search for specific value in ANY cell in a table?

Post by kmck » Thu Jul 25, 2013 12:54 pm

Hi Ciege,

I'm actually just using the regular Ranorex recorder module to achieve this. I use a Validate action with AttributeContains, Text, "Dan", Then the repository item pointing to the RanoreXPath (/container/container/table/row/cell[1]).

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Search for specific value in ANY cell in a table?

Post by krstcs » Thu Jul 25, 2013 1:13 pm

Instead of using the static index, you should try search for what you are trying to find.

If you want to find the cell whose innertext contains the name "David":

//table/row/cell[@innertext='David']


or if you are using a variable like "UserName":

//table/row/cell[@innertext=$UserName]

Just use Spy to find the attribute that contains the value you are looking for and put that attribute in the XPath for the object.


EDIT TO ADD:
Remember that you can also use all sorts of regular expressions in the XPath in order to match patterns and partial names, etc.
Shortcuts usually aren't...

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Search for specific value in ANY cell in a table?

Post by kmck » Thu Jul 25, 2013 1:29 pm

Thanks krstcs, that's how I had my repository set up before, but I wasn't sure if there was a way to keep it cleaner with less items and be able to use more general repository items rather than ones with specific strings attached to the RanoreXPath. But I guess I can't :P

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Search for specific value in ANY cell in a table?

Post by kmck » Mon Aug 12, 2013 5:24 pm

Ciege wrote:1) Can you show your code you are using? Will help debug it...

2) You can just as easily get an IList of all cells in a row or table and loop that IList looking for that cell data.

Example of how to get all Cells from a Table the loop those cells:

Code: Select all

IList<Ranorex.Cell> AllCells = MyTable.FindDescendants<Ranorex.Cell>();
foreach (Ranorex.Cell ThisCell in AllCells )
{
}
As an update, I tried this method as well and it worked great. Thanks, Ciege!

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Search for specific value in ANY cell in a table?

Post by Ciege » Mon Aug 12, 2013 5:48 pm

kmck wrote: As an update, I tried this method as well and it worked great. Thanks, Ciege!
Great!
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...