Clicking html element loaded by javascript (jquery live)

Kalashnikov

Junior Member
Joined
Feb 18, 2011
Messages
148
Reaction score
59
I'm having trouble with my bot, I'm trying to make it click an element that's loaded by javascript but it's not appearing in the elements list.

Any workarounds?
 
Are you using a webbrowser control?

If so maybe you could trigger it by setting the address as something like this:
Code:
javascript: $("#item").trigger('click'); void 0;
 
You should wait until window onload event is completed.
Maybe a thread sleep, but as we dont have any details about your bot, we cannot help you more.
 
@Chris22: A gotcha here is that $().trigger() does not work on events that where not binded by use of jQuery ;)
 
Ah, I sort of suspected so, but OP mentioned jQuery live so I figured it could be worth a shot.
 
Here's what I'm attempting to do, you see the blue comment bar:

Code:
soundcloud.com/tenaciousd/low-hangin-fruit

I tried clicking it via my bot for ages before searching through their javascript file and finding that it was loaded live, any ideas?

Currently my bot works flawlessly with the non timed comments but if I want to reach a bigger audience I need timed comments.

Any help would be appreciated.
 
Last edited:
But what kind of bot are you using?
Have you got source code?
Can you execute javascript on page?
 
Web browser bot, I've tried before without luck. If anyone could attempt to click the blue bar via a vb.net browser bot I'd appreciate it.
 
Web browser bot, I've tried before without luck. If anyone could attempt to click the blue bar via a vb.net browser bot I'd appreciate it.


This works for me: {sorry c#}

Code:
  void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
                return; 
            HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
            HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
            element.text = "function clickIt() { $('.timestamped-comments:first').click(); }";
            head.AppendChild(scriptEl);
            webBrowser1.Document.InvokeScript("clickIt");
        }
 
Ok this vb versio:

Code:
Private Sub webBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)  
  If e.Url.AbsolutePath <> TryCast(sender, WebBrowser).Url.AbsolutePath
 Then        Return    
End If    
Dim head As HtmlElement = webBrowser1.Document.GetElementsByTagName("head")(0)
Dim scriptEl As HtmlElement = webBrowser1.Document.CreateElement("script")    
Dim element As IHTMLScriptElement = DirectCast(scriptEl.DomElement, IHTMLScriptElement)    
element.text = "function clickIt() { $('.timestamped-comments:first').click(); }"
head.AppendChild(scriptEl)    
webBrowser1.Document.InvokeScript("clickIt")
End Sub
 
Ok this vb versio:

Code:
Private Sub webBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)  
  If e.Url.AbsolutePath <> TryCast(sender, WebBrowser).Url.AbsolutePath
 Then        Return    
End If    
Dim head As HtmlElement = webBrowser1.Document.GetElementsByTagName("head")(0)
Dim scriptEl As HtmlElement = webBrowser1.Document.CreateElement("script")    
Dim element As IHTMLScriptElement = DirectCast(scriptEl.DomElement, IHTMLScriptElement)    
element.text = "function clickIt() { $('.timestamped-comments:first').click(); }"
head.AppendChild(scriptEl)    
webBrowser1.Document.InvokeScript("clickIt")
End Sub

I can't seem to get the converted code to work in VB.. IHTMLScriptElement is undefined
 
You need to import mshtml

It is:
Code:
[/B][B]mshtml.[/B][COLOR=#FFFFCC]IHTMLScriptElement[/COLOR][B]
 
Last edited:
I see, my vb is crashing adding the reference. I'll try and fix it and get back to you.
 
Still can't add the reference, seems to be an issue with newer operating systems..
 
Back
Top