C# WebBrowser Invoke issue
- by James Jeffrey
I am logging into facebook using a web browser. Everything works, but the problem is when I invoke the button click I need to check if the password is correct but, the check seems to happen before the button is invoked which makes no sense at all because the checking code is after the invoke.
private void Facebook_Login(String username, String password)
{
webBrowser1.Url = new Uri("http://m.facebook.com");
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();
HtmlElementCollection inputs = webBrowser1.Document.GetElementsByTagName("input");
foreach(HtmlElement input in inputs)
{
if (input.GetAttribute("name") == "email")
{
input.SetAttribute("value", "[email protected]");
}
if (input.GetAttribute("name") == "pass")
{
input.SetAttribute("value", "kelaroostj"); // dont worry that pass wont work lol.
}
if (input.GetAttribute("name") == "login")
{
input.InvokeMember("click");
}
}
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();
HtmlElementCollection bs = webBrowser1.Document.GetElementsByTagName("b");
foreach(HtmlElement b in bs)
{
MessageBox.Show(b.InnerHtml);
}
Log_Message("Logged into Facebook with: [email protected]");
}