I am trying to login to my website automatically using webBrowser control in my C# application. The webpage checks the time required to fill and submit the login form. If the time taken is less than 2 seconds, then it shows an 'error page' saying 'Robots not allowed'.
Now my application is also getting that 'error page' just because the login form is getting filled within 2 seconds. How can I add a delay before firing the 'InvokeMember("click")' so that the time calculated by the webpage to fill the form be more than 2 seconds.
Here is my code
HtmlElement ele = WebBrowser1.Document.GetElementById("username");
if (ele != null)
{
ele.InnerText = "myUsrname";
}
ele = webBrowser1.Document.GetElementById("password");
if (ele != null)
{
ele.InnerText = "myPasswrd";
}
ele = webBrowser1.Document.GetElementById("submit");
if (ele != null)
{
// I want to add a delay of 3 seconds here
ele.InvokeMember("click");
}
Note : I used "Task.Delay(3000);" but it doesn't seems to work.
Edit : This is what I am using now and is working for me.
async void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
......//my code
await Task.Delay(3000);// this is where I wanted to put a delay
....
}
But I would like to, Is this a correct way to use it ?