WinForms Web Browser control forcing refocus?

Posted by Corey Ogburn on Stack Overflow See other posts from Stack Overflow or by Corey Ogburn
Published on 2010-02-21T22:26:11Z Indexed on 2010/03/08 21:36 UTC
Read the original article Hit count: 1110

Filed under:
|
|
|

I'm trying to automate a web process where I need to click a button repeatedly. When my code "clicks" that button (an HtmlElement obtained from the WebBrowser control I have on my form) then it brings focus back to my application, more specifically the WebBrowser control. I wish to better automate this process so that the user can do other things while the process is going on, but that can't happen if the window is unminimizing itself because it's attaining focus.

The code associated with the clicking is:

HtmlElement button = Recruiter.Document.GetElementById("recruit_link");
button.InvokeMember("click");

I've also tried button.RaiseEvent("onclick") and am getting the exact same results, with focus problems and all.

I've also tried hiding the form, but when the InvokeMember/RaiseEvent method is called, whatever I was working on loses focus but since the form is not visible then the focus seems to go nowhere.

The only non-default thing about the webbrowser is it's URI being set to my page and ScriptErrorsSuppressed being set to True.

© Stack Overflow or respective owner

Related posts about c#

Related posts about webbrowser