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?
Tries to get the TextField with id email and thus fails for the TextFieldExtended type.
Gets the TextFieldExtended with id email.