Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Working with lists

Cezary Piątek edited this page Apr 10, 2017 · 9 revisions

To simplify working with list there is a special wrapper called WebList. A list could be any html element which has collection of items (for example ul with li elements, table with tr, or even div with directly nested inner divs.

To create WebList wrapper from element with given id use code as follows

var list = browserAdapter.GetListWithId("SampleList");

You can also convert an existing element (IPageFragment) to list using ToWebList() method.

When you have WebList instance, you can access items using indexer notation

list[1] //access second child

or one of special methods

list.First() //access first child
list.Last() //access last child
list.FindItemWithText("Example child") //access child containing text 'Example child'

To get number of items use Count property.

Example: Click delete button in second row

<ul id="SampleList">
    <li>
        Item 1 <button>delete</button>
    </li>
    <li>
        Item 2 <button>delete</button>
    </li>
    <li>
        Item 3 <button>delete</button>
    </li>
</ul>
var list = browserAdapter.GetListWithId("SampleList");
list[1].ClickOnElementWithText("delete");

or

var list = browserAdapter.GetListWithId("SampleList");
var item2 = list.FindItemWithText("Item 2");
item2.ClickOnElementWithText("delete");