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

Fill out forms on youtube (problem with javascript)

Discussion in 'Visual Basic .NET' started by Kuranyi, Apr 25, 2010.

  1. Kuranyi

    Kuranyi Junior Member

    Joined:
    Dec 21, 2009
    Messages:
    104
    Likes Received:
    51
    Hello,
    i want to write a small tool with vb.net which can leave comments on youtube videos. I use the webbrowser solution to navigate.
    But the problem is, that i don't know how to fill out a form on a youtube video, because everything needs javascript.

    For example i want to fill out the comment textarea. This is the html code:
    Code:
    <textarea class="watch-comment" name="comment" onfocus="yt.www.comments.watch5.inputFocus(this)" onblur="yt.www.comments.watch5.inputBlur(this)" oninput="yt.www.comments.watch5.updateCount(this)">Respond to this video...</textarea>
    Then this is my try to fill out the comment textarea:
    Code:
    For Each Element As HtmlElement In TextAreas
        If Element.GetAttribute("class").ToString.ToLower.Equals("watch-comment") = True Then
            Element.Focus()
            Element.SetAttribute("Value", "Test")
        End If
    Next
    But this doesn't work (there is no "Test" at the textarea, but the "Respond to this video..." isn't there too) dio maybe because of "oninput="yt.w.....". So i don't how i can "simulate" oninput there? Do you have an idea?

    Thanks for every answer and i hope you understand my description.
    Greetings, Kuranyi

     
  2. crashed

    crashed Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 13, 2008
    Messages:
    958
    Likes Received:
    1,198
    Occupation:
    Guru-slayer
    Location:
    Behind the VPN...
    Home Page:
    Set a breakpoint to see if you actually update any elements.

    Try something like...

    Code:
    Dim txt As HtmlElement = WebBrowser1.Document.GetElementById("comment")
    Dim btn As HtmlElement = WebBrowser1.Document.GetElementById("NAMEOFSUBMITBUTTOM")
    txt.SetAttribute("value","Awsome video")
    btn.InvokeMember("click")
    
    See this video if ya want a sample: http://vimeo.com/10298782
     
    • Thanks Thanks x 1
  3. Kuranyi

    Kuranyi Junior Member

    Joined:
    Dec 21, 2009
    Messages:
    104
    Likes Received:
    51
    Great that works! :) Thank you.
     
  4. prometheussoft

    prometheussoft Newbie

    Joined:
    Jun 29, 2010
    Messages:
    41
    Likes Received:
    41
    Occupation:
    DBA
    Location:
    Kailua, HI
    Home Page:
    Interesting, never thought of that.