【发布时间】:2011-06-24 01:41:24
【问题描述】:
我的桌面上打开了一个 Internet Explorer 页面。该网页的名称是 TEST。使用 user32.dll 中的 FindWindow(),我可以在窗口上获取处理程序。在此页面中,我有一个名为 Go 的按钮和两个名为 Name 和 Surname 的文本框。我怎样才能在网页上写下我的名字和姓氏,然后以编程方式单击 Go?谢了
【问题讨论】:
标签: c#
我的桌面上打开了一个 Internet Explorer 页面。该网页的名称是 TEST。使用 user32.dll 中的 FindWindow(),我可以在窗口上获取处理程序。在此页面中,我有一个名为 Go 的按钮和两个名为 Name 和 Surname 的文本框。我怎样才能在网页上写下我的名字和姓氏,然后以编程方式单击 Go?谢了
【问题讨论】:
标签: c#
更新外部窗口(@987654322@ 等)的常规方法将不起作用,因为 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();
}
}
【讨论】:
我不确定使用 Win32 (user32.dll) 实际可以解决什么问题,我已经说过 如果您尝试与 Web 服务器交互,那么您可以根据需要简单地使用 httprequest 和 httpresponse 类来获取和发布变量。
HttpWebRequest testRequest = (HttpWebRequest)WebRequest.Create("http://.....");
HttpWebResponse testResponse = (HttpWebResponse)testRequest.GetResponse();
string responseStatus = testResponse.StatusCode.ToString();
testResponse.Close();
http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx
如果您想测试或回复一组标准事件,那么您可能想看看 Fiddler
http://www.fiddler2.com/fiddler2/
【讨论】: