11

我有以下 HTML:

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

我想从 WatiN 输入文本:

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

但是找不到该字段。这是因为 WatiN 还不支持 HTML5 标签。我通过创建扩展的 TextField 类找到了解决方案:

[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);
    }
}

注册类型并运行代码后,它仍然不起作用。任何人都可以看到为什么或有人对此问题有其他解决方法吗?

4

1 回答 1

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

尝试获取带有 id email 的 TextField,因此 TextFieldExtended 类型失败。

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

获取带有 id email 的 TextFieldExtended。

于 2012-04-06T14:27:36.867 回答