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();.
When the first line of the code is executed, I get an exception,
"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?
So, how can I fix this exception? Or is there any other way to emulate focus on a field?
Thanks in advance.
One should use FireEvent() instead of InvokeMember().