How to click a Programmatically button - Button in WebBrowser (IE)

I searched the Internet and found examples for:

"How to click a button that is in a web browser (Internet Explorer) in C #?

And so the code works on Google ;

JS:

void ClickButton(string attribute, string attName) { HtmlElementCollection col = webBrowser1.Document.GetElementsByTagName("input"); foreach (HtmlElement element in col) { if (element.GetAttribute(attribute).Equals(attName)) { element.InvokeMember("click"); // Invoke the "Click" member of the button } } } 

But my webpage button has different tags. Thus, the program cannot detect to click it.

My main question: How to press this button programmatically?

HTML:

 <a class="orderContinue" href="Addresses" title="Sipar Ver">Sipar Devam</a> 
+4
source share
3 answers

Naturally, the code you posted will not find the tag you posted. It searches for labels of type input :

 webBrowser1.Document.GetElementsByTagName("input") 

But as you say (and demonstrate):

But my webpage button has different tags.

So you need to look for the tags (tags) that you are using. Something like that:

 webBrowser1.Document.GetElementsByTagName("a") 

This will return the anchor elements in the document. Then, of course, you need to find the specific (s) that you want to click. What does this line do:

 if (element.GetAttribute(attribute).Equals(attName)) 

Does it determine that the target tag is completely dependent on the values ​​for these variables, which I assume you know and can control.

+8
source

Try the following:

 webbrowser1.Document.GetElementById("Element_Id").RaiseEvent("onclick"); 

Hope this helps you.

0
source

Using jQuery, you can put a click event on this tag.
You want to place this code at the bottom of the page

 <script> $(document).ready(function() { $('.orderContinue').click(function() { alert('Sipar Ver has been clicked'); // More jQuery code... }); }); </script> 
-one
source

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


All Articles