InvokeMember ("Click") input tag does not fire onclick event in web browser

I use Dotnet Web Browser to click the Input Element - Button. When this click event is fired, it performs a JS function that generates captcha using Google Recaptcher, the source of which looks like a Recaptcha link . Now the problem is that I could not fire the onClick event , I use the following code:

HtmlElementCollection inputColl = HTMLDoc.GetElementsByTagName("input"); foreach (HtmlElement inputTag in inputColl) { string valueAttribute = inputTag.GetAttribute("value"); if (valueAttribute.ToLower() == "sign up") { inputTag.Focus(); inputTag.InvokeMember("Click"); break; } } 

I checked everything, I will catch the correct button, but I do not know why the onClick event is not triggered. Any suggestion is welcome.

+6
source share
5 answers
  • Add a link to Microsoft.mshtml;
  • Take a look at the example below:

      HtmlElementCollection inputColl = HTMLDoc.GetElementsByTagName("input"); foreach (HtmlElement inputTag in inputColl) { string valueAttribute = inputTag.GetAttribute("value"); if (valueAttribute.ToLower() == "sign up") { inputTag.Focus(); IHTMLElement nativeElement = el.DomElement as IHTMLElement; nativeElement.click(); break; } } 
+3
source

That should work for sure. I tested it on Anchors and DIvs that contain an onclick event.

 HtmlElementCollection inputColl = HTMLDoc.GetElementsByTagName("input"); foreach (HtmlElement inputTag in inputColl) { string valueAttribute = inputTag.GetAttribute("value"); if (valueAttribute.ToLower() == "sign up") { obj = inputTag.DomElement; mi = obj.GetType().GetMethod("click"); mi.Invoke(obj, new object[0]); } } 

I was not able to open the link to see the code, so I did not try this on your specific case. In any case, if this does not work, can the TAG container be inserted into the form, in this case you need to fire the form submission event, and not click on the sorm submit button.

In any case, can your code work if you name "click" as a lowercase (I really didn’t check, I just wondered if the nut was in C #!).

PS: see Webbrowser: a sequence of actions when no DocumentCompleted is launched by a link on a hosted web page for some interesting side code for you, hope this helps and maybe someone helps me get back!

+1
source

Are you sure "Click" is the correct name? I have an almost identical code to do the same, and the attribute name is "onclick". Look again at the HTML for the page.

  foreach (HtmlElement element in col) { if (element.GetAttribute(attribute).Equals(attName)) { // Invoke the "Click" member of the button element.InvokeMember("onclick"); } } 
0
source

Try

 if (inputTag.InnerHtml == "sign up" || inputTag.InnerText.Contains("sign up")) { inputTag.InvokeMember("click"); } 

Just play with the conditions, check if you have typed the correct button. BTW, small case "click" on InvokeMember. This is what I use and it works for me.

0
source

Since you already have the object in focus, try sending the ENTER key as follows:

 SendKeys.Send("{ENTER}") 
-1
source

Source: https://habr.com/ru/post/893202/


All Articles