VS 2010 [resolved] InvokeMember("click") Javascript event (2fast for website) Help Fixit? :-)-VBForums
Results 1 to 6 of 6

Thread: [resolved] InvokeMember("click") Javascript event (2fast for website) Help Fixit? :-)

  1. #1

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Red face [resolved] InvokeMember("click") Javascript event (2fast for website) Help Fixit? :-)

    Code:
           For Each h As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")     ' * sends suprise teddy bear to a random forum member every 15
                If h.OuterHtml.ToLower.Contains("Give_ForumUser_TedBear") Then
                    h.InvokeMember("click")
                End If
            Next
    Edit: I put the code at the top, so I could save everybody time from reading my entire post if they don't recognize the code type!

    Hey guys another fresh newbie question!
    Some of you may know I run my own little web forum for a non-profit organization thingy. And that I'm making a program to automate some of my every day tasks as the administrator of it.
    I recently added the ability to send 'gifts' (like smiley faces & teddy bears) to members as like a nice thing to make people smile.

    Anyway when I'm reviewing new forum users profiles, I have a timer set to "click on send a teddy bear" on whomever's page I happen to b on at a 15 min interval.
    The text on the actual link (before sending) says "Send Teddy Bear" & after clicking it will say "Unsend Teddy Bear" in case you sent it on mistake.
    Problem (besides being a dummy newb) is when this code sends a click to this javascript event/link - the webpage is slow or something to receive the click I think. It always gets sent (from vb), sometimes its just slow for the link to change from "Send Teddy Bear" To "Unsend Teddy Bear" on the webpage. And it almost seems as if it clicks it more than once sometimes, which means it SENDS & THEN UNSEND'S the teddy bear! How can I make sure it only sends the click 1 time?
    So my forum users will have their teddy bear & lots of my forum members will be happy with me. Because aren't we all just seeking approval & love in this crazy upsidedown world!

    So any ideas vbforum guys? On how I can make sure it only sends the click once, no matter if the javascript link text is still the 'same' (because it hasn't changed yet, due to server bring slow)
    Thanks for taking the time to read my thread. I really appreciate all the helpful people here, you guys are a blessing!
    Last edited by jalexander; Oct 31st, 2012 at 07:34 PM. Reason: resolved
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  2. #2

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    InvokeMember("click") Javascript event

    Figured I would mention this is on a normal / html / webpage. On a remote server & I'm using a WebBrowser Control inside a typical windows form (visual basic 2010).
    So nothing complicated or anything. Maybe I'm just missing a loop, or am doing one without realizing it?

  3. #3
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    Re: InvokeMember("click") Javascript event

    Hi Jalexander

    Funnily enough im working on a similar project with HTML elements and all that jazz.

    if for the whole 'for each' loop you only intend to pick one person out, you could always put in an 'end for' after invoking the click. also one thing that i have had problems with is the page not loading quick enough to sort this i have had to do this



    Code:
    while wb.readystate <> readystate.complete 
         application.doevents()
    end while
    
    and this 
    
    System.Threading.Thread.Sleep(5000)  ' this just to slow things down a bit
    Ian
    Last edited by 12many; Oct 24th, 2012 at 01:14 PM. Reason: poor grammer

  4. #4
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Re: InvokeMember("click") Javascript event (too fast for my website) Help Me Fixit? :

    Code:
    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    End Sub
    Or you could use the DocumentCompleted event?

    Maybe I'm just missing a loop, or am doing one without realizing it?
    For..Each..Next, that is a loop. So the answer to your question is yes, you are having it loop through each 'h'.

    Here is an example of document completed event

    vb .net Code:
    1. Private Sub wb_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
    2.         If LoggedIn = False Then
    3.             Login(wb)
    4.         Else
    5.             If InMainArea = False Then
    6.                 EnterMainArea(wb)
    7.             End IF
    8.        End If
    9. End Sub
    Last edited by thebuffalo; Oct 24th, 2012 at 01:26 PM.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: InvokeMember("click") Javascript event (too fast for my website) Help Me Fixit? :

    Faith in the DocumentCompleted event is often misplaced. It will fire several times on the average webpage, and many times on some. You still need to check that the content you want to interact with is amongst the items that have fully loaded and ensure that you don't trip the relevant action if there are further firings on the current page.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Re: InvokeMember("click") Javascript event (too fast for my website) Help Me Fixit? :

    Quote Originally Posted by dunfiddlin View Post
    Faith in the DocumentCompleted event is often misplaced. It will fire several times on the average webpage, and many times on some. You still need to check that the content you want to interact with is amongst the items that have fully loaded and ensure that you don't trip the relevant action if there are further firings on the current page.
    That is why I use the If LoggedIn as a boolean, so once I complete that part it sets it true and continues on to the next If statement. This is only good for certain situations though, mine was to login, go to the main area, then read the page(s).

    vb .net Code:
    1. Private Sub wb_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
    2.         If LoggedIn = False Then
    3.             Login(wb)
    4.         Else
    5.             If InMainArea = False Then
    6.                 EnterMainArea(wb)
    7.              Else
    8.                  'Do stuff here
    9.             End IF
    10.        End If
    11. End Sub
    12.     Private Sub Login(ByVal myWB As WebBrowser)
    13.         'Do stuff here
    14.         LoggedIn = True
    15.     End Sub
    16.     Private Sub EnterMainArea(ByVal myWB As WebBrowser)
    17. ' more stuff
    18.         myWB.Document.GetElementById("ctl00_Menus1_hlnkMainTyping").InvokeMember("Click")
    19.         InMainArea = True
    20.     End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.