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

2019-08-19 08:19发布

问题:

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