[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!
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?
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
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?
Quote:
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:
Private Sub wb_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
If LoggedIn = False Then
Login(wb)
Else
If InMainArea = False Then
EnterMainArea(wb)
End IF
End If
End Sub
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.
Re: InvokeMember("click") Javascript event (too fast for my website) Help Me Fixit? :
Quote:
Originally Posted by
dunfiddlin
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:
Private Sub wb_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wb.DocumentCompleted
If LoggedIn = False Then
Login(wb)
Else
If InMainArea = False Then
EnterMainArea(wb)
Else
'Do stuff here
End IF
End If
End Sub
Private Sub Login(ByVal myWB As WebBrowser)
'Do stuff here
LoggedIn = True
End Sub
Private Sub EnterMainArea(ByVal myWB As WebBrowser)
' more stuff
myWB.Document.GetElementById("ctl00_Menus1_hlnkMainTyping").InvokeMember("Click")
InMainArea = True
End Sub