Hi
I am trying to automate a Java web app.
There is a table in the application (that I want to control) which contains a number of rows (with about 8 columns).
I wish to be able to loop through the rows in C# and then click on the first column if it contains a certain "innertext" value in the third column.
I am new to Ranorex and am not sure how to do this.
The Ranorex path for the first row (and first text column) is as follows:
"/dom[@caption='PureDeal']/body/div[@id='dragArea']/div[@id='divOpenPositions']/div[@id='ifrOpenPositionsHolder']/iframe/body/div/div/table/tbody[2]/tr[@id='yui-rec11']/td[2]/div/a[@innertext='CellTextHere']"
Now I can replace the expression: @id='yui-rec11' with the number 1 for first row
but I when I remove the innertext expression it no longer finds the cell.
I wish to loop thru all rows and read the values of innertext in columns 1 and 3. If the match a criteria I wish to click on column 1.
Please help
Thanks
How to loop through rows in a table
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to loop through rows in a table
Hi!
What your are looking for is the foreach statment in C#.
Peter
Ranorex Support Team
What your are looking for is the foreach statment in C#.
You should code something like:markvanraalte wrote:I wish to loop thru all rows and read the values of innertext in columns 1 and 3. If the match a criteria I wish to click on column 1.
foreach (TrTag row in repo.Sample.TableBody.Find("./tr")) { IList<TdTag> cells = row.Find<TdTag>("./td"); if (cells.Count >= 3 && cells[0].InnerText == "SomeValue" && cells[2].InnerText == "SomeOtherValue") { cells[0].Click(); } }Regards,
Peter
Ranorex Support Team
-
- Posts: 13
- Joined: Thu Apr 15, 2010 4:34 pm
Re: How to loop through rows in a table
Thanks Peter
Thats really helpful.
Unfortunately I needed to reference tags that were lower down (within the /td element)
I solved it as follows:
foreach (TrTag row in repo.WebDocumentPureDeal.OpenPositionsWindow.TableBody.Find("./tr"))
{
IList<TdTag>cells = row.Find<TdTag>("./td");
ATag _securityCell = cells[0].Children[0].FindSingle("./a");
DivTag _positionCell = cells[2].FindSingle("./div");
if ("SomeValue" == _securityCell.InnerText
&& "AnotherValue" == _positionCell.InnerText)
etc
Presumably this is a reasonable thing to do? It seems to work fine.
Thats really helpful.
Unfortunately I needed to reference tags that were lower down (within the /td element)
I solved it as follows:
foreach (TrTag row in repo.WebDocumentPureDeal.OpenPositionsWindow.TableBody.Find("./tr"))
{
IList<TdTag>cells = row.Find<TdTag>("./td");
ATag _securityCell = cells[0].Children[0].FindSingle("./a");
DivTag _positionCell = cells[2].FindSingle("./div");
if ("SomeValue" == _securityCell.InnerText
&& "AnotherValue" == _positionCell.InnerText)
etc
Presumably this is a reasonable thing to do? It seems to work fine.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: How to loop through rows in a table
That's exactly how I would do itmarkvanraalte wrote:Presumably this is a reasonable thing to do? It seems to work fine.
Regards,
Alex
Ranorex Support Team