Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WatiN support for HTML5 tags

Tags:

watin

I have the following HTML:

<input type="email" id="email">

I want to type text into it from WatiN :

var field = Browser.TextField("email");
Assert.IsTrue(field.Exists);

But the field can't be found. This is because WatiN doesn't support HTML5 tags yet. I found a solution to this by creating an extended TextField-class:

[ElementTag("input", InputType = "text", Index = 0)]
[ElementTag("input", InputType = "password", Index = 1)]
[ElementTag("input", InputType = "textarea", Index = 2)]
[ElementTag("input", InputType = "hidden", Index = 3)]
[ElementTag("textarea", Index = 4)]
[ElementTag("input", InputType = "email", Index = 5)]
[ElementTag("input", InputType = "url", Index = 6)]
[ElementTag("input", InputType = "number", Index = 7)]
[ElementTag("input", InputType = "range", Index = 8)]
[ElementTag("input", InputType = "search", Index = 9)]
[ElementTag("input", InputType = "color", Index = 10)] 
public class TextFieldExtended : TextField
{
    public TextFieldExtended(DomContainer domContainer, INativeElement element)
        : base(domContainer, element)
    {
    }

    public TextFieldExtended(DomContainer domContainer, ElementFinder finder)
        : base(domContainer, finder)
    {
    }

    public static void Register()
    {
        Type typeToRegister = typeof (TextFieldExtended);
        ElementFactory.RegisterElementType(typeToRegister);
    }
}

After registering the type and running the code it still doesn't work. Can anyone see why or does anyone have another workaround for this problem?

like image 891
Simen eriksen Avatar asked Apr 05 '12 07:04

Simen eriksen


Video Answer


1 Answers

var field = Browser.TextField("email");

Tries to get the TextField with id email and thus fails for the TextFieldExtended type.

var field = Browser.ElementOfType<TextFieldExtended>("email");

Gets the TextFieldExtended with id email.

like image 168
Simen eriksen Avatar answered Jan 16 '23 14:01

Simen eriksen