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
  • 95,331
  • 80
  • 293
  • 426
Tom Smykowski
  • 24,566
  • 52
  • 155
  • 227

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,465
  • 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,508
  • 7
  • 39
  • 67
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,043
  • 25
  • 112
  • 172
Ehsan
  • 11
  • 1
0

Use InvokeMethhod on HtmlElement or Browser.InvokeScript function.

Alex Reitbort
  • 13,315
  • 1
  • 38
  • 61