tags:

views:

95

answers:

2

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

A: 

Hi,

Why do you need to create an ElementFinder instance? Most of the times this is all handled by WatiN. Could you explain your usage scenario for this?

Thanks, Jeroen

Jeroen van Menen
Most of the time yes but in my case no. I'm creating custom control extending WatiN Div class. That div is often reloaded using div. When it's reloaded instance becomes non existent and I have no way of getting information out of it. I will post more detailed explanation of my case in few days when I'm back from holidays.
Sergej Andrejev
+1  A: 

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"));
Sergej Andrejev