问题
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