0

I have a method which automates logging onto a website based on the authentication's input names, their values, and clicking on the "login" button. Once logged in, I want to navigate to a page that requires that authentication. I have tried this implementation as so below:

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";

    }

My problem is that the url is being set to go to "http://facebook.com/messages" before the authentication is completed. Is there a way I can wait until the authentication completes before navigating to a different url? Thanks.

Mike Richards
  • 939
  • 3
  • 14
  • 23
  • It depends on what item(submitButton)).click() does. If the click triggers a new window, you need to handle DocumentComplete in that window. – Sheng Jiang 蒋晟 Jul 23 '13 at 04:20

1 Answers1

0

Adding a Thread.Sleep(5000) should work in your case. 5000 is in milliseconds so it is actually 5 secs. You can increase the time as per your requirement.

Thanks.

Jash
  • 942
  • 4
  • 17
  • 40
  • That is if the login process is finished within 5 seconds. Adding more time to handle long load times for some sites would be undesirable if the page was already loaded – Mike Richards Jul 22 '13 at 17:16