Firstly, I should say that I need to use an Internet Explorer (IE9) object in my application, I can't use the webBrowser control. So, I want to emulate focus event on a field on a webpage:
webBrowser.Document.Forms[0].GetElementsByTagName("input")[0].InvokeMember("onFocus");
webBrowser.Document.Forms[0].GetElementsByTagName("input")[0].SetAttribute("value", "aaaa");
webBrowser.Document.Forms[0].GetElementsByTagName("input")[1].InvokeMember("onFocus");
webBrowser.Document.Forms[0].GetElementsByTagName("input")[1].SetAttribute("value", "bbbbb");
The webBrowser variable 开发者_如何转开发is public static SHDocVw.InternetExplorer webBrowser;
. Its value is set to new SHDocVw.InternetExplorer();
.
"System.MarshalByRefObject.InvokeMember(<...>)" Inaccessible due to protection level.
The function I use is private static
. Maybe it's connected with the fact that IE's Document is dynamic?
One should use FireEvent() instead of InvokeMember().
精彩评论