web浏览器的setAttribute不工作(密码字段) [英] Webbrowser SetAttribute not working (Password Field)

查看:559
本文介绍了web浏览器的setAttribute不工作(密码字段)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试着写一个程序,它会自动记录我在C#中的网页浏览器。这是code我目前使用的这个目的:

  HtmlElementCollection pageTextElements = loginBrowser.Document.GetElementsByTagName(输入);
        的foreach(在pageTextElements的HtmlElement元素)
        {
            如果(element.Name.Equals(用户名))
                element.SetAttribute(价值,this.UserName);
            如果(element.Name.Equals(密码))
                element.SetAttribute(价值,this.Password);
        }

这填补了用户名,但没有密码? ):
用Google搜索左右,但也有它开始它从来没有人回答的话题只有几个人。 /:

希望有人能帮助我。
这是AUF密码字段来源:

 <输入类型=密码值=MAXLENGTH =50大小=25NAME =密码级=bginput>


解决方案

您需要等到文档更新已经完成。 DocumentCompleted 事件的方法。

如果你想看看是怎么回事,对顶部创建一个表单以面板 web浏览器上底端。加入3 文本框,一个按钮和另一个文本框。下面的方框中的的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);

您将看到您表格上的密码框中正确填充。

韦恩

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">

解决方案

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

这篇关于web浏览器的setAttribute不工作(密码字段)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆