Reputation: 4342
I am working on a windows form application, and I was wondering how to access elements inside the webbrowser. Say for example there is an element like this <button class="btn btn_Roll">Roll Dice</button>
how do I get that elemenet and perdorm a click action?
I know you can acccess elements by id like so
HtmlDocument document = webBrowser1.Document;
HtmlElement example = document.GetElementById("some_id_here");
How is it done with class?
Upvotes: 1
Views: 120
Reputation: 1203
try:
var element = this.objWebBrowser.Document.GetElementsByTagName("button").
Cast<HtmlElement>().Where(e =>
e.GetAttribute("class")).
FirstOrDefault();
if(element == null) return;
element.InvokeMember("click");
Upvotes: 2