我的桌面上打开了一个 Internet Explorer 页面。网页名称为TEST。使用 user32.dll 中的 FindWindow() 我可以在窗口上获取处理程序。在此页面中,我有一个名为“Go”的按钮,还有两个名为“Name”和“Surname”的文本框。如何在网页中写下我的名字和姓氏,然后以编程方式单击“Go”?谢谢
更新外部窗口的正常方法(WM_SETTEXT
等)将不起作用,因为 IE 中的表单组件不是标准窗口,而是由 IE 本身呈现。
要操作它们,您需要通过 DOM 调用(或使用类似WaitN).
using mshtml; //.net ref microsoft.mshtml
using SHDocVw; //com ref `microsoft internet controls` + change ref to no embed interop
int HWND = 0x001C0C10; //your IE
foreach(InternetExplorer ie in new ShellWindowsClass()) {
//find the instance
if (ie.HWND == HWND) {
//get doc
HTMLDocument doc = (HTMLDocument)ie.Document;
doc.getElementsByName("name").item(0).value = "bob";
doc.getElementsByName("surname").item(0).value = "smith";
doc.getElementsByName("go").item(0).click();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)