C # COM component by operation IE browser (B): Use IHTMLDocument3 complete login

The first chapter describes how to open the site, this chapter introduce the use IHTMLDocument3 complete the login blog garden, following is the code:

  1. SHDocVw.InternetExplorer oBrowser = new SHDocVw.InternetExplorer();
  2. ;
  3. object objTargetFrameName = "_self";
  4. object objPostData = "";
  5. object objHeaders = "";
  6. oBrowser.Visible = true;
  7. oBrowser.Navigate("https://passport.cnblogs.com/user/signin", ref objFlags, ref objTargetFrameName, ref objPostData, ref objHeaders);
  8. while (true)
  9. {
  10. Thread.Sleep();
  11. if (oBrowser.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
  12. break;
  13. }
  14. IHTMLDocument3 doc3 = (IHTMLDocument3)oBrowser.Document;
  15. IHTMLInputElement txtUserName = (IHTMLInputElement)doc3.getElementById("input1");
  16. txtUserName . value = "your username" ;
  17. IHTMLInputElement txtPassWord = (IHTMLInputElement)doc3.getElementById("input2");
  18. txtPassword . value = "your password" ;
  19. doc3.getElementById("signin").click();

Using the above code successfully logged on to a garden blog, tidy up the following IHTMLDocument3 and related methods and properties:

IHTMLDocument3 way Explanation
attachEvent

IE11 from the start, using the addEventListener . The specified function is bound to an event, so that whenever an event is triggered on an object, the function is called.

createDocumentFragment Create a new document and returns a pointer to a pointer to the newly created document.
createTextNode

Create a text string from the specified value.

detachEvent Unbind the specified functions from the event, so that the function stop receiving notifications when an event is triggered.
getElementById Returns with the specified value id reference to the first object attribute.
getElementsByName The name acquired object set value of the attribute.
getElementsByTagName Element name based on the specified set of search objects.
recalc This element is obsolete and no longer used. Recalculates all the dynamic properties of the current document.
releaseCapture

Remove the mouse capture from the document in the current object.

IHTMLDocument3 properties and events Explanation
baseUrl  
to you Sets or retrieves a value indicating the reading order of the object.
documentElement Gets a reference to the document root.
enableDownload Set Enable download
inheritStyleSheets Yet Description
onbeforeeditfocus Before setting the focus
oncellchange When the source data changes
OnContextMenu When you press the right mouse button menu or via the keyboard trigger a page menu
onpropertychange When changing the property
onrowsdelete The current data record is deleted
onrowsinserted When the current data source you want to insert the new data
uniqueID Automatically generated unique identifier of the search target.
onstop Stop or leave
OnDataSetChanged When the source data changes
ondatasetcomplete When the data reception is completed
OnDataAvailable When all valid data has been read data source

This chapter describes the IHTMLDocument3, and log in using IHTMLDocument3 completed, the next chapter IHTMLDocument2 and usage.

Guess you like

Origin www.cnblogs.com/soundcode/p/11497121.html