Reputation: 179
I need to type something in a textbox
inside a web-browser control. Simply setting the value doesn't work because this doesn't run javascript.
So:
InvokeMember: I thought I could use invokemember for this(since there's InvokeMember("Click")
). But google is silent about keyboard events.
Focus the element and then send keys to the control. It works(Sendkeys.Send
), but only if the control is activated. If I switch to another window, it will send keys completely, but not where I want to.
Upvotes: 0
Views: 5886
Reputation: 51
You can, for each character, set it and call an event. In this example Im calling the keypress event. Call the event for the last character you typed.
he.setAttibtute("value", "a");
KeyEventArgs kea = new KeyEventArgs(Keys.A);
he.InvokeMember("onkeypress", kea);
Where he is the HtmlElement
Upvotes: 0
Reputation: 179
So... In case anybody is interested.
What is possible? Its possible to send keys to a window... Teoretically its possible to send keys to unactive window(using SendMessage() and PostMessage()), but practically nobody has successfully done this since WinXP & x32 times...
I didnt try myself, but there are people who was able to send keys using "SendInput". But this useless anyway, cause the function can only send keys to active window.
So... SendKeys.Send(which, i guess, is a wrapper for SendInput) is still the best way around.
Solution
I created a form(window) for my webbrowser control. I initialize it, but dont use "Show". Then i simply make this form active right before "SendKeys.Send"(dont forget to focus on both element(inside the control) and control(inside the form) as well). Since there is no form to show, user doesnt notice anything and keys go to the right window. If its needed, its possible to save the handle of window which was active previously and make it active again after the sending(so focus wont be lost).
Summary
Although im ok with this solution and i will use it, its far from perfect... If anybody finds something better, please let me know(even in distant future).
Upvotes: 2
Reputation: 4909
In case anyone bumps into this looking for a framework agnostic way to fire any HTML and Mouse event, have a look here: How to simulate a mouse click using JavaScript?
Upvotes: 0
Reputation: 6754
About this: 'Javaspript. Is there a way to find out what javascript runs when i change a value of textbox? I dont know much about java. Element's attributes dont have something like OnClick/OnKeyUp etc.'
To view all javascript you can use firebug plugin for firefox. It has corresponding tab.
More info: http://getfirebug.com/whatisfirebug/
You can set up a break point and view all javascript variables you want.
Upvotes: 0