Page 1 of 1

Search for specific value in ANY cell in a table?

Posted: Wed Jul 24, 2013 10:02 pm
by kmck
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?

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

Posted: Wed Jul 24, 2013 11:24 pm
by Ciege
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 )
{
}

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

Posted: Thu Jul 25, 2013 12:54 pm
by kmck
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]).

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

Posted: Thu Jul 25, 2013 1:13 pm
by krstcs
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.

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

Posted: Thu Jul 25, 2013 1:29 pm
by kmck
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

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

Posted: Mon Aug 12, 2013 5:24 pm
by kmck
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!

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

Posted: Mon Aug 12, 2013 5:48 pm
by Ciege
kmck wrote: As an update, I tried this method as well and it worked great. Thanks, Ciege!
Great!