using watin to test webpage

192 views Asked by At

I am using Watin to test this page but I am unable to get to the subpage of each row in the table.

http://www.domea.dk/sog-bolig/Ledige-boliger/Sider/default.aspx

Any idea how to loop through each row and click the link to the subpage.

I am able to get a hold of the table that holds each row using:

Table table_name = browser.Table(Find.ById("listTable"));

And then loop through each row using: foreach (TableRow currRow in table_name.TableRows) { var s = currRow.TableCell(Find.ByIndex(0)); }

But I don't know how to get the "onclick" event inside of the cell to be "clicked" using watin.

1

There are 1 answers

0
ProgrammerV5 On

If you want to click on each row link this is the code you need to use:

        using (var browser = new IE("http://www.domea.dk/sog-bolig/Ledige-boliger/Sider/default.aspx"))
        {
            Table table_name = browser.Table(Find.ById("listTable"));
            foreach (TableRow currRow in table_name.TableRows)
            {
                foreach (var c in currRow.TableCells)
                {
                    if (c.Links.Count > 0)
                    {
                        c.Links[0].Click();
                    }
                }
            }
        }

You were going good but needed to get to the link on each row before you can click on it. In sample code I'm using the first link found on the cell c.Links[0].Click(); if this is going to be used as a production code you need to check that the first link is the one you need, for example, checking that the URL of the link is going to xxxx or it contains a specific web page (.Contains) etc.