1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# javascript button click

Discussion in 'C, C++, C#' started by Sprouts, Aug 11, 2012.

  1. Sprouts

    Sprouts Regular Member

    Joined:
    Mar 20, 2010
    Messages:
    461
    Likes Received:
    324
    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.
     
  2. carnage_100101

    carnage_100101 BANNED BANNED

    Joined:
    Feb 17, 2011
    Messages:
    240
    Likes Received:
    163
    Loop through all button tags,Look for innerhtml that ONLY that button has,Once found click.
     
  3. Piotr__11

    Piotr__11 Junior Member

    Joined:
    Mar 13, 2012
    Messages:
    122
    Likes Received:
    69
    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 ;)