【问题标题】:IHTMLDocument2 wait until loaded after clickIHTMLDocument2 等到点击后加载
【发布时间】:2013-07-22 16:34:10
【问题描述】:

我有一种方法可以根据身份验证的输入名称、它们的值以及单击“登录”按钮自动登录到网站。登录后,我想导航到需要该身份验证的页面。我已经尝试过这个实现,如下所示:

private void authenticateWebpage(string username, string userValue, string password, string passwordValue, string submitButton)
    {
        mshtml.IHTMLDocument2 doc = ((mshtml.HTMLDocumentClass)webPage.Document);
        ((mshtml.IHTMLElement)doc.all.item(username)).setAttribute("value", userValue);
        ((mshtml.IHTMLElement)doc.all.item(password)).setAttribute("value", passwordValue);
        ((mshtml.HTMLInputElement)doc.all.item(submitButton)).click();
        doc.url = "http://facebook.com/messages";

    }

我的问题是在身份验证完成之前,url 被设置为去"http://facebook.com/messages"。有没有办法可以等到身份验证完成后再导航到不同的网址?谢谢。

【问题讨论】:

  • 这取决于 item(submitButton)).click() 的作用。如果点击触发新窗口,则需要在该窗口中处理 DocumentComplete。

标签: c# .net wpf mshtml


【解决方案1】:

添加 Thread.Sleep(5000) 应该适用于您的情况。 5000 以毫秒为单位,因此实际上是 5 秒。您可以根据需要增加时间。

谢谢。

【讨论】:

  • 即如果登录过程在 5 秒内完成。如果页面已经加载,则不希望为某些网站增加更多时间来处理较长的加载时间
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 2015-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多