C# javascript button click

Sprouts

Regular Member
Joined
Mar 20, 2010
Messages
464
Reaction score
328
Hey Guys,

I'm trying to create a simple youtube bot which posts a comment (with web browsers) as my first C# project but I'm having some troubles clicking the "Post" button which posts the comment.

This is the code I'm using to click regular buttons which have an id element in HTML:

PHP:
webYoutube.Document.GetElementById("signIn").InvokeMember("click");

but the button code in the HTML has no id - instead it uses javascript. Here's the button code:

PHP:
<button type="submit" class="comments-post yt-uix-button yt-uix-button-default" onclick=";return true;"  role="button"><span class="yt-uix-button-content">Post </span></button>

My question is: How do I click this button?

Thanks in Advance.
 
Loop through all button tags,Look for innerhtml that ONLY that button has,Once found click.
 
Code:
  HtmlElementCollection collection = wb1.Document.All;         foreach (HtmlElement  element in collection)
         {
             if (element.GetAttribute("onclick")==";return true;"&&element.GetAttribute("type")=="submit"&&element.GetAttribute("role")=="button")
             {
                 element.InvokeMember("click");
             }   
         }
 
        }

It should work ;)
 
Back
Top