C #: webbrowser framework webpage-assignment-Click Event-assignment in the drop-down box of the Framework webpage

Source: Internet
Author: User

Net Framework web pages automatically insert data, some information collected online

FirstWebbrowser webpage Loading

This . Webbrowser1.url =   New System. Uri ( " URL " , System. urikind. Absolute );

Assign a value to a text box that is generally not in a frame webpage Webbrowser1.document. getelementbyid ( " Text Box ID " ). Innertext =   " Weiling " ; // The value of the text box is assigned by ID.
Or:This. webbrowser1.document. All [" Text Box Name "]. Setattribute (" Value "," 0924 ");//The value of the text box is assigned by name.

Form submission can also be considered as a click event Htmlelement form=Webbrowser1.document. getelementbyid ("Formid");//Submit Form
Form. invokemember ("Submit");

Text in the framework webpage This box Assign value ," Framemain "Is framework Na Me Webbrowser1.document. Window. Frames [ " Framemain " ]. Document. getelementbyid ( " Txtxingming " ). Innertext =   " 521656 " ; // Framework Assignment
Note:Framemain is the framework name.

Frame webpage drop-down list Assignment Htmldocument Doc = Webbrowser1.document. Window. Frames [ " Framemain " ]. Document; // Frame drop-down box assignment
Htmlelement el = Doc. getelementbyid ( " Drpxingbie " );
El. setattribute ( " Selectedindex " , " 1 " );

 

Frame webpageText BoxAssignment
Code

Htmlelement tbuserid = Webbrowser1.document. Window. Frames [ 0 ]. Document. All [ " Username " ];
Tbuserid. setattribute ( " Value " , " K221 " );

htmlelement tbpasswd = webbrowser1.document. window. frames [ 0 ]. document. all [ " passwd " ];
tbpasswd. setattribute ( " value " , " 33311 " );

Htmldocument htmldoc = Webbrowser1.document. Window. Frames [ 0 ]. Document;
Foreach (Htmlelement H In Htmldoc. All)
{
If (H. getattribute ( " Type " ). Tostring () =   " Submit " )
{
If (H. getattribute ( " Value " ). Tostring () =   " OK " )
{
H. invokemember ( " Click " );
Break ;
}
}
}

 

 

Obtain the HTML page content in the framework

1. Get the source file of the frame.

MessageBox. Show (webbrowser1.document. Window. Frames ["Main"]. Document. Body. innerhtml );

2. Obtain the htmldocument interface of the frame.

Htmldocument Doc = (htmldocument) webbrowser1.document. domdocument;
Object J;
For (INT I = 0; I <Doc. parentwindow. frames. length; I ++)
{
J = I;
Htmlwindow2class frame = Doc. parentwindow. frames. Item (ref J) as htmlwindow2class;
If (frame. Name = "Main ")
{
Messagebox.show(frame.doc ument. Title );
}
}

3. Obtain the ihtmldocument2 interface of the frame.

Ihtmldocument2 Doc = (ihtmldocument2) webbrowser1.document. Window. Frames ["Main"]. Document. domdocument;

4. Get the clicked connection in the frame

Private void webbrowser1_navigating (Object sender, webbrowsernavigatingeventargs E)
{
String url = webbrowser1.document. Window. Frames ["Main"]. Document. activeelement. getattribute ("src ");
}

 

 

 

Webbrowser1.navigate (New uri ("Http://asd10000.com/"));

Webbrowser1.scripterrorssuppressed = true;
Webbrowser1.allowwebbrowserdrop = false;
Webbrowser1.webbrowsershortcutsenabled = false;
Webbrowser1.iswebbrowsercontextmenuenabled = false; // 'hide the right-click menu

 

Code

  If (Webbrowser1.document. Window. Frames =   Null )
Return ;

htmldocument doc = webbrowser1.document. domdocument as htmldocument;
htmlwindow window = webbrowser1.document. window. frames [ 0 ];
doc = window. document. domdocument as htmldocument;

htmlinputelementclass input = Doc. all. item ( " username " , 0 ) as htmlinputelementclass;
input. value = " 222an1 " ;

Input=Doc. All. Item ("Passwd",0)AsHtmlinputelementclass;
Input. Value= "222111";

Htmldocument htmldoc= Webbrowser1.document. Window. Frames [ 0 ]. Document;
Foreach (Htmlelement H In Htmldoc. All)
{
If (H. getattribute ( " Type " ). Tostring () =   " Submit " )
{
If (H. getattribute ( " Value " ). Tostring () =   " OK " )
{
H. invokemember ( " Click " );
Break ;
}
}
}

 

 

 

 

 

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.