Search code examples
watin

How to create ElementFinder in WatiN?


In WatiN RC1 how can I create ElementFinder which will find any element on page?


Solution

  • Here is what I found out.

    I can create ElementFinder using two ways

    First. When creating custom control (extending Div, Table and so on) there is a protected method CreateElementFinder<T>. Here is an example:

    var elementFinder = CreateElementFinder<Element>(
        nativeEl => nativeEl.AllDescendants,
        Find.ById("id"));
    

    Second. If you are not extending any control you can use NativeElementFinder constructor. Here is an example:

    var finder = new NativeElementFinder(
        () => browser.Body.NativeElement.AllDescendants,
        browser.DomContainer,
        new[] { ElementTag.Any },
        Find.ById("id"));