I am quite new in visual C# and I'm trying to code an auto login program. Basically all i need is to know SetAttribute and InvokeMember for now.
To simplify the task, I have tried to make a form that will go to google, use SetAttribute to change query box to the user input and use InvokeMember to click "search" button. However code ignores the InvokeMember function when I try to run them in order.
Here is my code:
webBrowser1.Navigate("www.google.com");
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
webBrowser1.Document.GetElementById("q").SetAttribute("value", searchTXT.Text);
//MessageBox.Show(webBrowser1.Document.GetElementById("q").GetAttribute("value"));
webBrowser1.Document.GetElementById("btnK").InvokeMember("click");
it basically ignores the last line. However when I uncomment the messagebox, it works. It also works when I use a seperate button for clicking, so last line itself should be okay.
I think it is some kind of a delay problem. So I have to wait SetAttribute to finish its job before I call InvokeMember. I tried a while loop to put some delay but it didnt work. Is there any way to wait an operation to complete before proceeding? Is it the actual cause of my problem?
I would really appreciate any help, Thanks in Advance!
Thread.Sleep(150);
System.Threading.Thread.Sleep(150);