简体   繁体   中英

Automate Form login in website using Webbrowser control

I'm automating form login in a certain site using the WebBrowser control. Having the client id of the textbox, password and button login, I'm able to do it.

The question is, can I still do it without identifying the id of the button and simulate a click?

Yes; you can call the submit method of the form object.

For example:

browser.Document.Forms[0].Invokemember("submit");

To set the name and password, loop through

browser.Document.Forms[0].GetElementsByTagName("input")

Tpassword will have the type attribute equal to password , and the username will probably be just before the password.

There is no way you could do this without being able to identify the controls somehow. You would need the ids, or you would need to be told exactly where in the DOM they were located by some other means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM