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

Problem clicking a button

Discussion in 'Visual Basic .NET' started by Kalashnikov, May 22, 2013.

  1. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    Basically I've hit a snag in my bot creation, I'm finding it impossible to click this button:

    [​IMG]

    I have tried absolutely everything I can think of, searching through the source until it finds it etc and trying to invoke a click. My guess is it's loaded dynamically? I've tried google searching but I've hit a wall, nothing I find seems to work.

    Any feedback would be great!
     
    • Thanks Thanks x 1
  2. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    Bump! Really stuck on this one guys :(
     
  3. theMagicNumber

    theMagicNumber Regular Member

    Joined:
    May 13, 2010
    Messages:
    345
    Likes Received:
    195
    You should share more details about your problem.
    If you are using web browser/selenium/watin/whatever browser emulation you shouldn't have problems.
    If you are using web requests, it'll be a little more complicated. Just download Fiddler and see what is happening, don't try to read and underestand the javascript and the html code, it is pointless.
     
    • Thanks Thanks x 1
  4. oozyluce

    oozyluce Regular Member

    Joined:
    Jan 26, 2013
    Messages:
    277
    Likes Received:
    231
    Occupation:
    IT Coordinator, Senior Network Administrator
    Location:
    http://www.gaben.tv/
    Home Page:
    We need more information on the engine you are using, like theMagicNumber has stated. If you use an engine that supports DOM manipulation, then nothing will be easier. However i doubt you are, as you would have not had this problem in the first place.

    So, let us know man
     
    • Thanks Thanks x 1
  5. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    Sorry for being vague!

    The onclick of the "dynamic"? Button is "addressBook.processNewForm('ab-newform');;return false;"

    I'm using basic vb.net internet browser controls (IE I think it is?)

    I tried doing something like this:
    Code:
            browser.Document.GetElementById("ab-button-new-contact").InvokeMember("click")        browser.Document.GetElementById("username").SetAttribute("Value", "username")
            For Each element As HtmlElement In browser.Document.GetElementsByTagName("span")
                If element.GetAttribute("class") = "yt-uix-button-content" Then
                    MsgBox("swag")
                    If element.GetAttribute("onclick") = "addressBook.processNewForm('ab-newform');;return false;" Then
                        MessageBox.Show("swag2")
                        element.InvokeMember("click")
                    End If
                End If
            Next
    It clicks the "Add" button and inputs the username but the save button never clicks.

    The reason I did the "OnClick" if statement is because both the cancel and the save buttons are id'd by "yt-uix-button-content"

    You can find the page I'm referring to at youtube.com/address_book
     
    Last edited: May 24, 2013
  6. theMagicNumber

    theMagicNumber Regular Member

    Joined:
    May 13, 2010
    Messages:
    345
    Likes Received:
    195
    You should get the <button> element, not the <span>.
     
  7. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    I tried button before span, have tried everything. Still no joy :/
     
  8. YouTubez

    YouTubez Regular Member

    Joined:
    Feb 3, 2013
    Messages:
    327
    Likes Received:
    140
    Occupation:
    YouTube Marketing
    I would honesty go with selenium man, its a lot faster and built more for what your trying to do.

    hope I helped
     
  9. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    Never heard of it, I shall look into it

    Edit, is this separate from vb.net? I'm confused?
     
    Last edited: May 25, 2013
  10. oozyluce

    oozyluce Regular Member

    Joined:
    Jan 26, 2013
    Messages:
    277
    Likes Received:
    231
    Occupation:
    IT Coordinator, Senior Network Administrator
    Location:
    http://www.gaben.tv/
    Home Page:
    It's a library, a Package... Not sure it exists for VB.net. i always wrote selenium in Java

    Check it out: http://docs.seleniumhq.org/
     
  11. oozyluce

    oozyluce Regular Member

    Joined:
    Jan 26, 2013
    Messages:
    277
    Likes Received:
    231
    Occupation:
    IT Coordinator, Senior Network Administrator
    Location:
    http://www.gaben.tv/
    Home Page:
    You say that the cancel and the save button has the same Id, first off, they don't have an id, they have a class.
    From there, here's what i would suggest you to do:

    Instead of invoking the singular getElement method, i would invoke the plural one, i.e: getElements, with an "S"!
    I would also invoke getElementsByClassName, which is supported by every modern browser now.

    Since the method getElements with an "S" returns an array of all the matching elements, you can make it select the first " yt-uix-button yt-uix-button-primary", which should be the "save" button.

    I've never done vb.net, but you could try something like this:

    Code:
    browser.Document.GetElementsByClassName(" yt-uix-button yt-uix-button-primary")[0].InvokeMember("click");
     
  12. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    By ID I was referring to anything that makes these particular elements unique, whether it be class name etc... unfortunately vb.net doesn't have a "GetElementByClassName" but I coded a function to do just that, like I said i think it's loaded dynamically so it's not working at all :(
     
  13. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    I hate to bump... but I'm really stuck on this guys...
     
  14. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    you could just execute the javascript:
    Code:
    addressBook.processNewForm('ab-newform');
    
    with something like browser.Document.InvokeScript("eval",args) and args is an object array with the script as string, sorry don't know shit about vb
     
  15. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    Cheers man, I think I'm just gonna recode the bot in c#... vb seems too sensitive with some things it seems
     
  16. dragonrage01

    dragonrage01 Power Member

    Joined:
    May 19, 2011
    Messages:
    674
    Likes Received:
    155
    I'm not really good with vb.net but I have my own program or bots.
    There are so many websites that I can't click the submit button or save button.
    So I make my bot use the mouse and make it click on the webbrowser1 coordinates that I give it.
    It works all the time. Having said that the button must be visible in my webbrowser1 so I often make it scroll down.
     
  17. Kalashnikov

    Kalashnikov Junior Member

    Joined:
    Feb 18, 2011
    Messages:
    148
    Likes Received:
    59
    Location:
    Northern Ireland
    I've thought about doing that, but I can't seem to figure out the exact coordinates... got an example?
     
    Last edited: May 31, 2013
  18. oozyluce

    oozyluce Regular Member

    Joined:
    Jan 26, 2013
    Messages:
    277
    Likes Received:
    231
    Occupation:
    IT Coordinator, Senior Network Administrator
    Location:
    http://www.gaben.tv/
    Home Page:
    Are you sure about the non-existence of this method? Like i said before i've never coded in VB.net but according to MSDN... it does exist: http://msdn.microsoft.com/en-us/library/ie/ff975198(v=vs.85).aspx

    Also... I don't think it's created dynamically, every time i visit the url it's always the same class name, meaning it doesn't change on page refresh, which would mean that get elements by class name would work.

    But providing that it DOES get loaded dynamically... Do it the RAW way baby :)

    the "save" button is the 15th button element on that page. Make sure it's the 15th for you too tho.

    Code:
    browser.Document.GetElementsByTagName("button")[15].InvokeMember("click");