Simulate a Click in WebBrowser using C #

2

I would like to know how to do a click on a button on a website even by clicking on such a debug web element in the browser itself.

I'm using the C # webbrowser component

I have tried some methods here, but without success, even using GetElementsByTagName

and in the html of the site is this way.

<button type="button" ng-click="confirmarPresenca()">ENTRADA</button>

I tried with the following code but with no success in my Windows Form Application C #

HtmlElementCollection el = webBrowser1.Document.GetElementsByTagName("button");
foreach(HtmlElement btn in el)
{
    if(btn.GetAttribute("type").Equals("button")
    {
         btn.InvokeMember("click");
    }
}
    
asked by anonymous 23.07.2014 / 20:25

2 answers

1

It would be in the case that you click on a button for a specific WEB URL. The first button it had the following part in HTML

<input type="submit" value="Entrar" name="commit"></input>

the code to be able to click this button as follows

//Clica no Botão Entrar Após Preenchimento dos Campos
HtmlElementCollection doc1 = this.webBrowser1.Document.GetElementsByTagName("input");
foreach(HtmlElement doc00 in doc1)
{
    //Opção 2
    if(doc00.GetAttribute("type").Equals("submit"))
    {
        doc00.InvokeMember("click");
    }
}

But after he logs in to a certain URL, which has been filled in with the login and password fields, there is another page that he enters, containing the following HTML code snippet, which is a button too and wanted to invoke a click on it.

<button ng-click="confirmarPresenca()" type="button"></button>

But as mentioned above, I already tried to get the button and attribute element and I did not have a return, and I wanted some method I could call this button according to that HTML above

    
29.07.2014 / 05:30
1

SNOT, you can use the HtmlAgilityPack or CsQuery APIs, among others, in your project. If you check NUGET you will find them. They make it possible to use CSS search to retrieve DOM objects.

But if in case you are going to continue using only System.Windows.Forms.WebBrowser , I indicate using GetElementsByTagName("button") and by array you get to the element you want to execute the click.

    
13.05.2017 / 08:21