Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate keypress in a non-visible webbrowser object C#

I'm currently working in an application that has to navigate a webpage and recollect data about products, prices, ... with webbrowser object in .net 3.5.

The problem is that the page has some fields with a suggest script in ajax, and I can't simply modify the innerText property because the script also saves codes in a hidden input field.

I need a way to simulate the typing in that field and then send the "Enter" key, or launch the ajax script and then send the "Enter" key, or any better ways to do this.

like image 743
Artanis Avatar asked Jan 02 '26 06:01

Artanis


2 Answers

Use Watin

Then you can use this solution.

like image 183
Mischa Kroon Avatar answered Jan 03 '26 20:01

Mischa Kroon


To submit a form or run a script you can do this: If you know the script name you can use InvoekScript of Document object:

myWebBrowser.Document.InvokeScript("script-name",null);

the second argument is an array of objects to pass parameters values.

if you know the name of an element that it's click event fires the script you can do this:

HtmlElement element=myWebBrower.Document.GetElementById("element-name")[0];
element.InvokeMember("click");
like image 39
Beatles1692 Avatar answered Jan 03 '26 18:01

Beatles1692



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!