我试着编写一个程序,在c#中的webbrowser中自动登录。 这是我目前用于此目的的代码:
HtmlElementCollection pageTextElements = loginBrowser.Document.GetElementsByTagName("input"); foreach (HtmlElement element in pageTextElements) { if (element.Name.Equals("username")) element.SetAttribute("value", this.UserName); if (element.Name.Equals("password")) element.SetAttribute("value", this.Password); }它填写用户名,但不填写密码? ):谷歌搜索,但只有少数人开始没有人回复的主题。 /:
希望有人可以帮助我。 这是密码字段的源码:
<input type="password" value="" maxlength="50" size="25" name="password" class="bginput">tried to write a program which logs me in automatically in a webbrowser in c#. This is the code i use at the moment for this purpose:
HtmlElementCollection pageTextElements = loginBrowser.Document.GetElementsByTagName("input"); foreach (HtmlElement element in pageTextElements) { if (element.Name.Equals("username")) element.SetAttribute("value", this.UserName); if (element.Name.Equals("password")) element.SetAttribute("value", this.Password); }It fills in the Username, but not the password? ): Googled around but there are only a few people which started topic to which no one ever replied. /:
hopefully someone can help me. this is the source auf the password field:
<input type="password" value="" maxlength="50" size="25" name="password" class="bginput">最满意答案
您需要等到文档更新完成。 DocumentCompleted事件方法。
如果要查看发生了什么,请创建一个顶部为Panel ,底部为WebBrowser的表单。 添加3个TextBox ,一个Button和另一个TextBox 。 以下框的OnClick方法执行以下操作:
webBrowser1.Document.GetElementById(this.textBox1.Text).SetAttribute(this.textBox2.Text, this.textBox3.Text); this.textBox4.Text = webBrowser1.Document.GetElementById(this.textBox1.Text).GetAttribute(this.textBox2.Text);您将看到表单上的“ Password框正确填充。
韦恩
You need to wait until the document updating has been completed. DocumentCompleted event method.
If you want to see what is going on create a form with a Panel on top and a WebBrowser on the bottom. Add 3 TextBoxes, a Button and another TextBox. The OnClick method of the following box do the following:
webBrowser1.Document.GetElementById(this.textBox1.Text).SetAttribute(this.textBox2.Text, this.textBox3.Text); this.textBox4.Text = webBrowser1.Document.GetElementById(this.textBox1.Text).GetAttribute(this.textBox2.Text);You'll see that your Password box on you form populates correctly.
Wayne
更多推荐
发布评论