|
-
Dec 9th, 2007, 02:31 PM
#1
Thread Starter
New Member
Solved [2005] HTML Doc event triggering and AJAX in a client-side app
I need to build a client side application that will load a webpage and automate several tasks, i.e. programmatically trigger the onclick event below and so on.
I've come up with the following code that works well up until I get to the last batch of elements I need to simulate a click on.
Here's the code.
Code:
ListBox1.Items.Clear()
Try
'get number of elements in the document
Tot = WebBrowserMain.Document.All.Count
TextBox1.Clear()
'generate list of clickable elements only
For I = 0 To Tot - 1
CurrentLink = WebBrowserMain.Document.All(I).getattribute("ID").ToString
If InStr(CurrentLink, "fgh") > 0 Then
ListBox1.Items.Add(CurrentLink.ToString)
temp = I
'ok so we got an element "I", that contains the right IDs
'now trigger the internal event
hElement = WebBrowserMain.Document.All(I)
hElement.ScrollIntoView(True)
hElement.InvokeMember("onclick")
Log("Clicked link")
End If
Next
Log("END")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
And here's the html that's relevant, it contains AJAX.
Code:
<div id="app2437228683_diggComment3435209" fbcontext="7c279ec28a71">
<center>
<a style="cursor: pointer;" onclick="fbjs_sandbox.instances.a2437228683.bootstrap();return fbjs_dom.eventHandler.call([js_dom.get_instance(this,2437228683),function(a2437228683_event) {a2437228683_doajax('Comment3435209', 'http://74.86.142.204/~tearswep/humanpets/diggComments.php?cid=3435209&up=1&diggs=2&poster=556985114&herd=1', '')},2437228683],new js_event(event));return true">
<img src="http://x.x.x.x/up.jpg" width="30" height="30" /></a><br />
When run the code works fine for buttons, checkboxes etc, but stalls on this onclick event, and I don't know why. I imagine it's because that although contained within the ID of the element I've captured, the event itself isn't named, or perhaps there's something else preventing it. I'm not a developer, and I only use VB on occasion, so any help is greatly appreciated!
Last edited by katanshin; Dec 9th, 2007 at 07:30 PM.
Reason: Solved
-
Dec 9th, 2007, 02:35 PM
#2
Re: Please help with HTML Doc parsing with VB2005 client-side app
Welcome to the Forums
You can get some guidensce and tips from this thread - http://vbforums.com/showthread.php?t=416275
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 9th, 2007, 03:20 PM
#3
Thread Starter
New Member
Re: Please help with HTML Doc parsing with VB2005 client-side app
Hi, and thanks for the quick response and welcome!
I encountered this thread earlier and whilst it's a great start for some things I might need in future, doesn't address my particular issue.
Last edited by katanshin; Dec 9th, 2007 at 03:23 PM.
-
Dec 9th, 2007, 03:33 PM
#4
Re: [2005] HTML Doc event triggering and AJAX in a client-side app
Since it doesnt have a name or id then you may have better luck looping through the HTMLLinkElements and clicking them.
Dim link As MSHTML.HTMLLinkElement
'set link to the desired element and then ...
link.Click
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 9th, 2007, 03:41 PM
#5
Thread Starter
New Member
Re: [2005] HTML Doc event triggering and AJAX in a client-side app
Thanks again, I'm not sure how to implement that idea in the above code, I was using the newer web controls up until an hour ago and need to familiarise myself with the older COM stuff.
Any help with this is appreciated!
-
Dec 9th, 2007, 03:52 PM
#6
Re: [2005] HTML Doc event triggering and AJAX in a client-side app
Something like this will enumerate all the links but you will need some way to know if you should click it or not.
Code:
Dim doc As MSHTML.HTMLDocument
Dim link As MSHTML.HTMLLinkElement
Dim i As Integer
WebBrowser1.Navigate2 "http://vbforums.com"
'Wait for doc to load. Maybe put in other event.
Set doc = WebBrowser1.Document
For Each link In doc.links
If link.Title = "Something" Then
link.Click
End If
Next
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 9th, 2007, 04:32 PM
#7
Thread Starter
New Member
Re: [2005] HTML Doc event triggering and AJAX in a client-side app
From what I can see this is exactly what I've already done.
My code iterates through all elements in the document looking for the right ID, then invokemember("onclick")s the right link.
I've followed the syntax using 2005 controls and I end up having to use either raiseevent("onclick"), or invokemember("onclick"), to simulate the click, with zero effect.
-
Dec 9th, 2007, 04:41 PM
#8
Thread Starter
New Member
Re: [2005] HTML Doc event triggering and AJAX in a client-side app
This may shed some light: I've discovered that when using getattribute("onclick"), there is no text returned, so possibly there is no effect because although the HTML indicates that onclick is there, the code isn't finding it...
-
Dec 9th, 2007, 07:30 PM
#9
Thread Starter
New Member
Re: [2005] HTML Doc event triggering and AJAX in a client-side app
Alright, I fixed the issue by scanning through the document for the "src" attribute containing the image name I needed to click, then using the raiseevent("click") command on it.
Phew. Thanks all!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|