using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri("http://www.gmail.com");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement txtUserHtml = webBrowser1.Document.All["Email"];
HtmlElement txtPasswordHtml = webBrowser1.Document.All["Passwd"];
HtmlElement btnClickHtml = webBrowser1.Document.All["signIn"];
txtUserHtml.SetAttribute("value", "这里填写用户名");//输入用户名
txtPasswordHtml.SetAttribute("value", "这里填写密码");//输入密码
btnClickHtml.InvokeMember("click");
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri("http://www.gmail.com");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement txtUserHtml = webBrowser1.Document.All["Email"];
HtmlElement txtPasswordHtml = webBrowser1.Document.All["Passwd"];
HtmlElement btnClickHtml = webBrowser1.Document.All["signIn"];
txtUserHtml.SetAttribute("value", "这里填写用户名");//输入用户名
txtPasswordHtml.SetAttribute("value", "这里填写密码");//输入密码
btnClickHtml.InvokeMember("click");
}
}
}
本文介绍了一个简单的C#应用程序,该程序使用Windows Forms和WebBrowser控件自动登录Gmail。通过设置HtmlElement的属性并模拟点击行为,程序实现了自动填写用户名和密码并提交表单的功能。
1940

被折叠的 条评论
为什么被折叠?



