WatiN:运行代码时,文本字段没有自动化
WatiN.Core.IE 窗口 = new WatiN.Core.IE();
// Frames
// Model
TextField txt_txtName = window.TextField(Find.ByName("txtName"));
TextField txt_txtPassword = window.TextField(Find.ByName("txtPassword"));
Button btn_btnLogin = window.Button(Find.ByName("btnLogin"));
// Code
window.GoTo("http://134.554.444.55/asdfgfghh/");
txt_txtName.TypeText("fghfjghm");
txt_txtPassword.TypeText("gfhgjfgh");
btn_btnLogin.Click();
}
只有 window.GoTo("http://134.554.444.55/asdfgfghh/");代码有效,其余部分什么都不做,
当我使用 catch 块时,它会抛出异常,因为
找不到 INPUT(隐藏)或 INPUT(密码)或 INPUT(文本)或 INPUT(文本区域)或 TEXTAREA 元素标记匹配条件:属性“name”等于“http://134.554.444.55/asdfgfghh/”处的“txtName”(内部异常:无法转换 COM 对象将“System.__ComObject”键入到接口类型“mshtml.IHTMLElement”。此操作失败,因为对 IID 为“{3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}”的接口的 COM 组件上的 QueryInterface 调用由于以下错误而失败。 :加载类型库/DLL 时出错(HRESULT 异常:0x80029C4A) (TYPE_E_CANTLOADLIBRARY))。)
WatiN.Core.IE window = new WatiN.Core.IE();
// Frames
// Model
TextField txt_txtName = window.TextField(Find.ByName("txtName"));
TextField txt_txtPassword = window.TextField(Find.ByName("txtPassword"));
Button btn_btnLogin = window.Button(Find.ByName("btnLogin"));
// Code
window.GoTo("http://134.554.444.55/asdfgfghh/");
txt_txtName.TypeText("fghfjghm");
txt_txtPassword.TypeText("gfhgjfgh");
btn_btnLogin.Click();
}
only the window.GoTo("http://134.554.444.55/asdfgfghh/"); code works and the rest are doing nothing,
When I am using a catch block it throws exception as
Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'txtName' at "http://134.554.444.55/asdfgfghh/ (inner exception: Unable to cast COM object of type 'System.__ComObject' to interface type 'mshtml.IHTMLElement'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的答案与 Pavlo 的答案非常相似,但我必须建议使用
Page
,它是 Pavlo 所描述的Model
的内置支持。创建一个类 MyPage
然后你可以调用
.Page
方法。My answer is very similar with Pavlo's one, but I must advice to use
Page
which is a built-in suport forModel
as described by Pavlo.Create a class MyPage
Then you can just call
.Page<MyClass>
method.当您调用 Button、TextField 或其他不会创建映射的内容时,它实际上会在页面上搜索控件。如果页面尚未打开,则控件不存在。
您可以创建在您请求时找到控制权的属性。因此,您将特定模型定义为具有适当属性的类。
已添加:如果创建属性不适合您,请使用以下命令:
When you call Button, TextField or whatever it does not create mapping it actually searches for control on page. And if the page is not opened yet than control does not exist.
You can create properties that will find control when you request it. So you define a particular model as class with appropriate properties.
Added: If creating properties does not work for you, then use this: