I recently worked as an intern at the company. I had to get stuck every time I went to work. When I first arrived, I always forgot! But I had to write a timed entry into the company's OA card.Program! During the writing process, it was found that buttons (images and hyperlinks) on the company's OA system (website) were difficult to find. After analyzing the webpage source code, it was found that the company's OA system was deployed in frame layout, for precise positioning, I recursively traverse all the frames of the OA system andCodeAll are mined! To locate the elements you want to obtain!
// Webbrowser first sets the URL and then fills in the data (account and password) to automatically log on to Oa. After the website is loaded, the analysis framework starts.
// Here I put the Framework Structure on the Treeview tree control.
Private hashtable htframe = new hashtable (); // key: Framework name value: Framework object
Private hashtable htframecontent = new hashtable (); // key: Framework name value: HTML code in the framework
Private void button#click (Object sender, eventargs E)
{
Treeview1.nodes. Clear ();
Htframe. Clear ();
Htframecontent. Clear ();
Treeview1.nodes. Add ("frames"); // Root Node
Fillframe (treeview1.nodes [0], webbrowser1.document. Window. Frames); // call
}
// Traverse all frameworks
Private void fillframe (treenode TN, htmlwindowcollection HWC)
{
If (HWC = NULL) return;
Foreach (htmlwindow HW in HWC)
{
Treenode tmpnode = tn. nodes. Add (TN. Text + "--" + HW. Name); // prevent sub-frameworks in different frameworks from having the same name
Htframe. Add (tmpnode. Text, HW); // frame name and frame object
Htframecontent. Add (tmpnode. Text, HW. Document. Body. innerhtml); // framework name and HTML in the framework
If (HW. frames. Count> 0) fillframe (tmpnode, HW. Frames );
}
}