1. Gets the value of the element, based on the element ID.
For example to get This the value of the SRC attribute in the tag:
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 out the form and determine
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 the source code
TextBox1.Text = Doc2.body.innerHTML;
4. Execute JS
Mshtml. IHTMLWindow2 win = (mshtml. IHTMLWINDOW2) Doc2.parentwindow;
Win.execscript ("changeregimg ()", "JavaScript");//Use JS
5, prohibit JS,WPF under the current discovery only applicable one method:
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);
}
WPF WebBrowser Control-critical code