Web浏览器SetAttribute无法正常工作(密码字段)(Webbrowser SetAttribute not working (Password Field))

编程入门 行业动态 更新时间:2024-10-26 14:32:34
Web浏览器SetAttribute无法正常工作(密码字段)(Webbrowser SetAttribute not working (Password Field))

我试着编写一个程序,在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

更多推荐

本文发布于:2023-08-03 20:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1401138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   无法正常   浏览器   密码   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!