日期:2014-05-17 浏览次数:21696 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace tzbao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//开始
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.****.com/logon.html");
}
//在web浏览器控件中承载的文档全部加载后发生。
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
switch (webBrowser1.Url.ToString())
{
case "https://www.****.com/logon.html": login(); break;
}
}
private void login()
{
var username = webBrowser1.Document.GetElementById("logonUsername");
var password = webBrowser1.Document.GetElementById("password");
var logonAction = webBrowser1.Document.GetElementById("logonAction");
username.InnerText = loginUsername.Text;
password.InnerText = loginpassword.Text;
logonAction.InvokeMember("Click");
}
}
}