Simulate click on WebBrowser using C #

0

I wanted to know how to do a click on an element of a website (at the end), I would like it to click on that element.

href="javascript:;" class="spot drugdealer" title="Traficante de drogas"

I tried to use .GetAttribute() , along with InvokeMember("click") , but I did not succeed.

    
asked by anonymous 25.05.2014 / 06:26

1 answer

3

Assuming you are using the WebBrowser class. If the element you want to click contains a id you can simulate a click like this:

webBrowser1.Document.GetElementById("id").InvokeMember("click");

The information provided by you did not mention whether there is some id or not, just the spot drugdealer class, to simulate a click on an element through its class, do:

HtmlElementCollection classButton = webBrowser1.Document.All;
foreach (HtmlElement element in classButton) 
{
    if (element.GetAttribute("className") == "spot drugdealer")
    {
        element.InvokeMember("click");
    }
}
    
25.05.2014 / 13:42