简体   繁体   English

使用Webbrowser控件自动在网站中登录表单

[英]Automate Form login in website using Webbrowser control

I'm automating form login in a certain site using the WebBrowser control. 我正在使用WebBrowser控件在某个站点中自动进行表单登录。 Having the client id of the textbox, password and button login, I'm able to do it. 有了文本框的客户端ID,密码和按钮登录名,我就能做到。

The question is, can I still do it without identifying the id of the button and simulate a click? 问题是,我是否仍可以在不标识按钮ID并模拟点击的情况下执行此操作?

Yes; 是; you can call the submit method of the form object. 您可以调用form对象的submit方法。

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. Tpassword的type属性将等于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. 您可能需要ID,或者需要通过其他方式准确告知它们在DOM中的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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