关于在WebBrowser里打开的网页里输入内容,操作网页的问题
我想弄一个注册一个网站的程序,在winform里有两个button和一个webBrowser控件,代码如下,想了很久都还是不会怎么在webBrowser控件打开的网页里填写内容,然后实现自动注册的功能,有高手帮帮忙…… 小弟qq联系[Discuz!]&Menu=yes" target="_blank">" border="0">联系我public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e) //这个按钮是打开网页
{
string url = "http://signup.
webBrowser1.Navigate(url);
/* System.Uri url = new Uri("http://signup.);
webBrowser1.Url = url ;
*/
}
private void button1_Click(object sender, EventArgs e) //实现自动填写的按钮事件
{
string name = txtName.Text;
string age = txtAge.Text;
string pwd = txtPwd.Text;
string rpwd = txtPwd.Text;
HtmlDocument doc = null;
doc = webBrowser1.Document;
HtmlElement btnSubmit = webBrowser1.Document.All["submitbutton"];
HtmlElement tbUserid = webBrowser1.Document.All["username"];
HtmlElement tbPasswd = webBrowser1.Document.All["password"];
if (tbUserid == null || tbPasswd == null || btnSubmit == null)
return;
tbUserid.SetAttribute("value",name);
tbPasswd.SetAttribute("value", pwd);
btnSubmit.InvokeMember("click"); ;
HtmlElement formLogin = webBrowser1.Document.Forms["loginForm"];
//……
formLogin.InvokeMember("submit");
}
}