Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Linq and Watin to grab HTML table

Status
Not open for further replies.

EvolMonster

Programmer
Aug 14, 2006
41
GB
Hiya guys

Ok, here's the setup.
I am using Watin to navigate through a website. When I reach a certain page, I am grabbing the table details, and looking for a certain bit of text, so I can grab the next indexed cell.

To do this, i am navigating using the Watin addon, and Linq, to query the table and its rows / cells.

The code looks like :
----------------------------------------------------------
public static string GetNextCellText(this WatiN.Core.IE ie, string searchText)
{
var rowValue = (from rTable in ie.Tables.Cast<Table>()
from rRow in rTable.TableRows.Cast<TableRow>()
from resultsCell in rRow.TableCells.Cast<TableCell>()
where resultsCell.Text.StartsWith(searchText)
select new
{
CellIndex = resultsCell.Index,
Row = rTable.TableCells,
RowIndex = rRow.Index
}
).First();

int Index = rowValue.RowIndex + 1;
TableCell returnValue = rowValue.Row[Index];
return returnValue.Text;
-----------------------------------------------------------

Hope that formatted ok!

So, the problem is, when I search for some text, the returned cell is always the first cell in the table.
I then add one to the cell, and it goes to index 1. But the problem is, the cell I want is in index 3!

Could it be, that even though I am comparing the cell text, and returning this cell, the fact that I am returning the first cell, means that index 0 is always returned?

Thanks!
DB
 
Well I thought that, but, esentially Watin is passing a HTML table to the above code, which is using Linq to scan the table.
So is it not a linq issue maybe?

 
yes, linq is where the problem is occuring, but your using it against watin. the source of the error may originate from watin. then again maybe watin is irrevelant and distracting me from the root problem.

not to distract from your original problem, but are you using Watin for unit testing? if so, is that working well? it's one of the tools i want to integrate into my testing model but haven't had the time.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Watin is excellent!
We are using it for testing, and to retrieve data from some of our partners websites, when they dont have a webservice.

Can highly recommend it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top