پر کردن فیلدهای سایت Yahoo
در زیر کد مربوط به ورود به سایت یاهو آورده شده است. برنامه ویندوزی ایجاد کرده و یک کنترل Timer و یک کنترل WebBrowser بر روی فرم قرار دهید. نکته ای که در کد زیر وجود دارد این است که به جای hamid@yahoo.com و 123، ایمیل و پسورد خودتان را وارد کنید.
using System; using System.Windows.Forms; namespace Webbrowser1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.webBrowser1.Navigate("https://en-maktoob.yahoo.com/?p=us"); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (this.webBrowser1.Document.Url.AbsoluteUri == "https://en-maktoob.yahoo.com/?p=us") { HtmlElementCollection allLinks = this.webBrowser1.Document.GetElementsByTagName("a"); HtmlElement signInElement = null; for (int i = 0; i < allLinks.Count; i++) { if (allLinks[i].GetAttribute("href").StartsWith("https://login.yahoo.com/config/login?")) { signInElement = allLinks[i]; break; } } if (signInElement != null) { signInElement.InvokeMember("click"); } } if (this.webBrowser1.Document.Url.AbsoluteUri == "https://login.yahoo.com/config/login?.src=fpctx&.intl=xe&.lang=en-JO&.done=https://en-maktoob.yahoo.com/%3fp=us") { HtmlElement usernameElement = this.webBrowser1.Document.GetElementById("login-username"); if (usernameElement != null) { usernameElement.InnerText = "hamid@yahoo.com"; } if (usernameElement.GetAttribute("aria-hidden") == string.Empty) { HtmlElement signInElement = this.webBrowser1.Document.GetElementById("login-signin"); if (signInElement != null) { signInElement.InvokeMember("click"); } this.timer1.Start(); } } } private void timer1_Tick(object sender, EventArgs e) { HtmlElement passwordElement = this.webBrowser1.Document.GetElementById("login-passwd"); if (passwordElement != null) { if (passwordElement.GetAttribute("aria-hidden") == string.Empty) { passwordElement.InnerText = "123"; HtmlElement signInElement = this.webBrowser1.Document.GetElementById("login-signin"); if (signInElement != null) { signInElement.InvokeMember("click"); } this.timer1.Stop(); } } } } }