Simulate click on Webbrowser using C#

Asked

Viewed 802 times

0

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

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

I’ve tried using the .GetAttribute(), along with the InvokeMember("click") but I was unsuccessful.

  • Hello. When the title refers to webbrowser, it refers to your browser or class WebBrowser?

  • 1

    I’m talking about the browser we can add to our form.

1 answer

3


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

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

The information provided by you did not mention whether there is any id or not, just the class spot drugdealer, 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");
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.