IHTMLDocument2在单击后等待加载



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

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"。有没有一种方法可以让我等到身份验证完成后再导航到另一个url?谢谢

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

谢谢。

最新更新