WatiN support for HTML5 tags

不羁岁月 提交于 2019-12-18 04:02:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10024178/watin-support-for-html5-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!