Xixi-C #-webbrowser-Logon-data filling-simulate click link-run JS function-check whether the webpage is loaded

Source: Internet
Author: User
C #, webbrowser, logon, data filling, simulated click link, run JS function, check whether the webpage is loaded and whether the network is normal private bool isconnectedtointernet () {int DESC; return Internet. internetgetconnectedstate (Out DESC, 0);} sets the default page: webbrowser1.navigate (New uri ("http://www.ic2ic.com/copy.jsp"); login code: Private void btnlogin_click (Object sender, eventargs e) {webbrowser1.document. getelementbyid ("ID "). innertext = txtuser. text. tostring (). trim (); // fill name webbrowser1.document. getelementbyid ("passwd "). innertext = txtpwd. text. tostring (). trim (); // fill PWD htmlelement formlogin = webbrowser1.document. forms ["frmlogin"]; formlogin. invokemember ("Submit"); thread. sleep (5000); herfclick ("http://www.ic2ic.com/upload.jsp"); // This is a successful login operation, jump to // upload. ASP // Note that the link is not directly skipped. // The session will not be lost.Herfclick ("http://www.ic2ic.com/copy.jsp");} simulated click link: Private void herfclick (string URL) {for (INT I = 0; I <webbrowser1.document. All. Count; I ++ ){
If (webbrowser1.document. All [I]. tagname = ""&&
Webbrowser1.document. All [I]. getattribute ("href"). tostring (). Trim ()
= URL) {webbrowser1.document. all [I]. invokemember ("click"); // trigger the "click" event break; }}} run the JS function private void calljsmethod (string jsfun, string jsparameter) in the webpage // function name, function parameter {htmldocument Doc = webbrowser1.document; Doc. invokescript (jsfun, new object []... {jsparameter});} fill data: Private void filldate (string txt) {htmlelement frmword = webbrowser1.document. forms ["frmword"]; // find from htmlelementcollection txtarea = frmword. getelementsbytagname ("textarea"); htmlelementcollection radio = frmword. getelementsbytagname ("input"); radio [2]. invokemember ("click"); // select the radio control txtarea [0]. innertext = TXT. tostring () ;}the principle is very simple. In the documentcompleted event of webbrowser1, judge the current completed URL address. If the current completed URL is equal to the URL to be opened, determine whether the current webpage has been loaded. // the URL of the page to be opened by string strurl
Private void webbrowserappsdocumentcompleted (Object sender, webbrowserdocumentcompletedeventargs E)
{
If (E. url. tostring (). Trim () = strurl. Trim ())
{
// Load completed
} Control the flow bar webbrowser1.document. Window. scrollto (100,100); // scroll to the coordinates you want, in pixels
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.