Since the WPF webbrowser control is very different from the winform webbrowser control, it was tossed around for a night, and now some keyCodeSummarize.
The Microsoft. mshtml. dll address must be c: \ Program Files \ Microsoft. NET \ primary InterOP assemblies.
1. Obtain the element value based on the element ID.
For example, to obtain the value of the src attribute in this label:
Mshtml. ihtmldocument2 doc2 = (mshtml. ihtmldocument2) webbrowser1.document;
Mshtml. ihtmlelement IMG = (mshtml. ihtmlelement) doc2.all. Item ("regimg", 0 );
String imgurl = (string) IMG. getattribute ("src ");
2. Fill in the form and confirm
Mshtml. ihtmlelement loginname = (mshtml. ihtmlelement) doc2.all. Item ("loginname", 0 );
Mshtml. ihtmlelement loginpw = (mshtml. ihtmlelement) doc2.all. Item ("password", 0 );
Mshtml. ihtmlelement loginbt = (mshtml. ihtmlelement) doc2.all. Item ("formsubmit", 0 );
Mshtml. ihtmlelement loginyz = (mshtml. ihtmlelement) doc2.all. Item ("regcode", 0 );
Loginname. setattribute ("value", tbloginname. Text );
Loginpw. setattribute ("value", tbloginpassword. Password );
Loginyz. setattribute ("value", tbyz. Text );
Loginbt. Click ();
3. Get source code
Textbox1.text = doc2.body. innerhtml;
4. Execute JS
Mshtml. ihtmlwindow2 win = (mshtml. ihtmlwindow2) doc2.parentwindow;
Win.exe cscript ("changeregimg ()", "JavaScript"); // use JS
5. Disable Js. Currently, the only applicable method found in WPF is:
Public void hidescripterrors (webbrowser WB, bool hide)
{
Fieldinfo ficomwebbrowser = typeof (webbrowser). getfield ("_ axiwebbrowser2", bindingflags. instance | bindingflags. nonpublic );
If (ficomwebbrowser = NULL) return;
Object objcomwebbrowser = ficomwebbrowser. getvalue (WB );
If (objcomwebbrowser = NULL) return;
Objcomwebbrowser. GetType (). invokemember (
"Silent", bindingflags. setproperty, null, objcomwebbrowser, new object [] {hide });
}
Void webbrowser1_navigated (Object sender, navigationeventargs E)
{
Hidescripterrors (webbrowser1,
True );
}