Webbrowser: JavaScript on the execution page

Source: Internet
Author: User

After obtaining a page, webbrowser can execute script functions on the page. For example

Htmlelement. invokemember () method

Or

Htmldocument Doc = webbrowser1.document;

Doc. invokescript (jsfun, new object []... {jsparameter });

 

But does Java's httpclient seem to be okay?

 

The following is an article about using webbrowser to implement this task:

C #, webbrowser, login, data filling, analog click link, run JS function (http://www.outdosoft.com/winfrom/57372116J.html)

 

 

Determine whether the network is normal

Private bool isconnectedtointernet ()

{

Int DESC;

Return Internet. internetgetconnectedstate (Out DESC, 0 );

}

Set the default page:

Webbrowser1.navigate (New uri ("http://www.ic2ic.com/copy.jsp "));

Logon 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 = "A" & webbrowser1.document. all [I]. getattribute ("href "). tostring (). trim () = URL)

{

Webbrowser1.document. All [I]. invokemember ("click"); // triggers the "click" event.

Break;

}

}

}

Run JS functions on the webpage

Private void calljsmethod (string jsfun, string jsparameter) // 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 ();

}

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.