【问题标题】:SendMessage user32dll on an internet explorer pageInternet Explorer 页面上的 SendMessage user32dll
【发布时间】:2011-06-24 01:41:24
【问题描述】:

我的桌面上打开了一个 Internet Explorer 页面。该网页的名称是 TEST。使用 user32.dll 中的 FindWindow(),我可以在窗口上获取处理程序。在此页面中,我有一个名为 Go 的按钮和两个名为 Name 和 Surname 的文本框。我怎样才能在网页上写下我的名字和姓氏,然后以编程方式单击 Go?谢了

【问题讨论】:

    标签: c#


    【解决方案1】:

    更新外部窗口(@98​​7654322@ 等)的常规方法将不起作用,因为 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();
       }
    }
    

    【讨论】:

      【解决方案2】:

      我不确定使用 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/
      

      【讨论】:

        猜你喜欢
        • 2010-09-18
        • 1970-01-01
        • 2012-10-02
        • 1970-01-01
        • 1970-01-01
        • 2013-08-09
        • 2011-02-07
        • 2016-02-26
        • 2017-06-04
        相关资源
        最近更新 更多