Tuesday, November 8, 2016

Login to Facebook account using Webbrowser and LINQ

Hi,
Here's how to login to your facebook account using Webbrowser control and LINQ in Windows Forms. The input elements are checked through their attributes like "email" for email fields, "password" for password fields and "submit" for submission control. These codes are inside the DocumentCompleted event.
C# code
WebBrowser1.Document.GetElementsByTagName("input").Cast<HtmlElement>().FirstOrDefault(t => t.GetAttribute("type") == "email").SetAttribute("value", "your email address");
WebBrowser1.Document.GetElementsByTagName("input").Cast<HtmlElement>().FirstOrDefault(t => t.GetAttribute("type") == "password").SetAttribute("value", "your user name");
WebBrowser1.Document.GetElementsByTagName("input").Cast<HtmlElement>().FirstOrDefault(t => t.GetAttribute("type") == "submit").InvokeMember("click");       
VB.NET Code
WebBrowser1.Document.GetElementsByTagName("input").Cast(Of HtmlElement)().FirstOrDefault(Function(t) t.GetAttribute("type") = "email").SetAttribute("value", "your email address")
WebBrowser1.Document.GetElementsByTagName("input").Cast(Of HtmlElement)().FirstOrDefault(Function(t) t.GetAttribute("type") = "password").SetAttribute("value", "your user name")
WebBrowser1.Document.GetElementsByTagName("input").Cast(Of HtmlElement)().FirstOrDefault(Function(t) t.GetAttribute("type") = "submit").InvokeMember("click")

0 comments:

Post a Comment