This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Working with tables
Cezary Piątek edited this page Apr 10, 2017
·
2 revisions
To simplify working with tables there is a special wrapper called WebTable. A table could be a html <table>
tag with or without <thead>
and <tbody>
element or any other tag composition in the following format:
<container>
<row>
<col>Row 0 Col 0</col>
<col>Row 0 Col 1</col>
</row>
<row>
<col>Row 1 Col 0</col>
<col>Row 1 Col 1</col>
</row>
</container>
To create WebList wrapper from element with given id use code as follows
var table = browserAdapter.GetTableWithId("SampleTable");
You can also convert an existing element (IPageFragment) to table using ToWebTable() method.
When you have WebTable instance, you can access items and columns using indexer notation
table[1] //access second row
table[1][0] //access second row, first column
table[1][0].Text //access second row, first column cell's text
table[0]["Column Name"] //access first row, column with caption "Column Name"
or one of special methods
list.First() //access first row
list.First().First() //access first row, first column
list.Last().Last() //access last row, last column
list.FindItemWithText("Example row")[1] //access row with text "Example row", second column
To get number of rows use Count property.
<table id="SampleTable">
<thead>
<tr>
<th>Lp</th>
<th>First name</th>
<th>Last name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Nash</td>
<td><button>Delete</button></td>
</tr>
<tr>
<td>2</td>
<td>Steve</td>
<td>Jobs</td>
<td><button>Delete</button></td>
</tr>
</tbody>
</table>
var table = browserAdapter.GetTableWithId("SampleTable");
table[1].ClickOnElementWithText("Delete");
or
var table = browserAdapter.GetTableWithId("SampleTable");
table[1][2].ClickOnElementWithText("Delete");
var table = browserAdapter.GetTableWithId("SampleTable");
Console.WriteLine(table[0]["First name"].Text);