我有以下HTML:

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

我想从WatiN中输入文本:
var field = Browser.TextField("email");
Assert.IsTrue(field.Exists);

但是找不到该字段。这是因为WatiN尚不支持HTML5标签。
我通过创建扩展的TextField类找到了一个solution:
[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);
    }
}

注册类型并运行代码后,它仍然不起作用。谁能看到原因,或者任何人都有其他解决方法来解决此问题?

最佳答案

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

尝试获取带有ID电子邮件的TextField,因此对于TextFieldExtended类型失败。
var field = Browser.ElementOfType<TextFieldExtended>("email");

获取带有ID电子邮件的TextFieldExtended。

关于WatiN对HTML5标签的支持,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10024178/

10-10 23:21