Sending/Setting a value to a Password Field on a Website

僤鯓⒐⒋嵵緔 提交于 2019-12-25 01:38:56

问题


I have written a small application that needs to log in to a website to perform some actions. The problem is that whenever I try to set the password field on the website it doesn't accept the password.

I have found a way around this by using the SendKeys function. The problem with that is that it requires focus and the program requires to run in the background.

Is there a way to do this?

Here is an example of how you'd set the Username Field:

WebBrowser.Document.GetElementById("field-username").SetAttribute("value", "UserName")

Any help would be great.


回答1:


The answer to this question is as follows:

WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("maxLength", "20")
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("value", "yourpassword")

By changing the "maxlength" value it allows you to set the "value" to the desired text and then you can submit the Form and it will accept it.




回答2:


Try with mshtml or Html Agility Pack



来源:https://stackoverflow.com/questions/11903313/sending-setting-a-value-to-a-password-field-on-a-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!