当您按提交按钮时,我希望文本框中的数据填充到WebBrowser(Windows表单内(,并且要按下登录按钮
我在任何地方都找不到答案,我想用它来制作自动化的东西
我目前没有代码 webBrowser1.Navigate("https://en-gb.facebook.com/");
当前它不起作用,但我想以简单的方式找出如何做到这一点,因为我擅长于C#尚未表现出的外观,这将使我的问题变得更有意义
以下代码将帮助您
形式加载事件
private void Form_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://en-gb.facebook.com/");
}
按钮单击事件
private void button1_Click(object sender, EventArgs e)
{
// User name
HtmlElement userElement = (from HtmlElement element in webBrowser1.Document.GetElementsByTagName("input") select element)
.Where(x=>x.Id == "email").FirstOrDefault();
if (userElement != null)
{
userElement.SetAttribute("value", textBox1.Text);
}
// Password
HtmlElement passwordElement = (from HtmlElement element in webBrowser1.Document.GetElementsByTagName("input") select element)
.Where(x => x.Id == "pass").FirstOrDefault();
if (passwordElement != null)
{
passwordElement.SetAttribute("value", textBox2.Text);
}
// Submit
HtmlElement submitElement = (from HtmlElement element in webBrowser1.Document.GetElementsByTagName("input") select element)
.Where(x => x.Id == "u_0_a").FirstOrDefault();
if (submitElement != null)
{
submitElement.InvokeMember("click");
}
}