سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top