There is a program with the WebBrowser component and a text field on the site that intercepts keydown. Before that I worked through focus and sendkeys, but the problem is that when switching to another window it stops working. After which he wrote the following command:

mainweb.Url = new Uri("javascript:" + "document.getElementById('double_your_btc_stake').value = '0.000002';" + "document.getElementById('double_your_btc_stake').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 0x20}));"); 

But, unfortunately, this:

 document.getElementById('double_your_btc_stake').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 0x20})); 

does not work in IE. In the IE console itself, writes "The command is not supported by the object.

Who can tell a software keydown emulation on a page element in a webbrowser?

UPD: I found this solution, IE takes it:

 $(document.getElementById('double_your_btc_stake')).keydown(); 

but if you do this:

  mainweb.Url = new Uri("javascript:$(document.getElementById('double_your_btc_stake')).keydown();"); 

then the result object is displayed in WebBrowser as [Object object], but you need to stay on the page.

  • If you have solved the problem yourself, please issue a solution as an answer. - awesoon

1 answer 1

At the moment, a solution has been found:

  mainweb.Document.GetElementById("double_your_btc_stake").SetAttribute("value", "0.000002"); HtmlDocument doc = mainweb.Document; HtmlElement head = doc.GetElementsByTagName("head")[0]; HtmlElement s = doc.CreateElement("script"); s.SetAttribute("text", "function keyEvent() { $(document.getElementById('double_your_btc_stake')).keydown(); }"); head.AppendChild(s); mainweb.Document.InvokeScript("keyEvent");