我有以下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);
}
}
注册类型并运行代码后,它仍然无效。任何人都可以看到为什么或有没有人有这个问题的另一种解决方法?
答案 0 :(得分:14)
var field = Browser.TextField("email");
尝试使用id电子邮件获取TextField,因此TextFieldExtended类型失败。
var field = Browser.ElementOfType<TextFieldExtended>("email");
获取带有id email的TextFieldExtended。