0

I have opened a website using WebBrowser. Now I would like to programmatically click input text (textbox) field. I can not use focus because this website uses JS to unlock this field only if it's clicked and I've tried also this:

Object obj = ele.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]); 

But it returns mi = null. How to do this so it will work?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236

4 Answers4

2

Very similar to my answer on your other question.

Get an HtmlElement respresentative of your textbox, and call HtmlElement.InvokeMember("click") on it.

Community
  • 1
  • 1
Cam Soper
  • 1,499
  • 9
  • 10
1

If you can, use:

webbrowser1.Navigate("javascript:document.forms[0].submit()")

or something similar. For me, it's been much easier and more accurate.

Eyal
  • 5,728
  • 7
  • 43
  • 70
1

To fill-up a text field on a webpage:

string code ="";
code = code + "var MyVar=document.getElementById('tbxFieldNameOnWebPage');if(MyVar != null) MyVar.value = 'SOMEVALUE';";
domDocument.parentWindow.execScript(code, "JScript");

Then To Click a button on a webpage:

code = "";
code = "var SignupFree = document.getElementsByTagName('button')[1];";
code = (code + " SignupFree.click();");
domDocument.parentWindow.execScript(code, "JScript");

you can also use document.getElementById('buttonID'); instead of document.getElementsByTagName('button')[1]; but an id must be provided for this button on that particular webpage.

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
Ehsan
  • 11
  • 1
0

Use InvokeMethhod on HtmlElement or Browser.InvokeScript function.

Alex Reitbort
  • 13,504
  • 1
  • 40
  • 61