-
Jun 30th, 2012, 12:05 AM
#1
Thread Starter
Junior Member
How do I click a javascript button?
I am working on a home project to automate a task so I can improve my time management.
I am using a web browser control and need to automate the process of clicking a javascript button. I have tried to click the button by it's value but it is not working and I cannot click the button by it's ID also.
This is the code of the webpage button I need my software to automatically click:
Code:
<a href="javascript:void(0);" onclick="viewvideo(7656,'ZYPbX7dNaPw');">Next</a>
Note that the random looking numbers and letters within the parentheses in the "onclick" part of the code changes every time the page reloads.
I have already searched in these forums and found a thread regarding this same issue but still not able to get it working.
I have tried messing with this code I found on another thread, but with no luck:
Code:
WebBrowser1.Document.All("Submit").RaiseEvent("onclick")
I have been researching this issue for months now on and off when I had the time and am coming to a loss now.
Any help is very greatly appreciated.
Thanks in advance,
David.
I dream in VB...
Do
If Sun > 0 Then
Sun.Visible = False
Conscious.Enabled = False
End If
Loop
-
Jun 30th, 2012, 11:07 AM
#2
Re: How do I click a javascript button?
As we don't have any idea of what you've tried it's kinda difficult to be too helpful. However as I've been searching unsuccessfully for a browser macro engine that would do this very thing I'm beginning to think that it is impossible by trying to invoke the click. There appears to be some disjunction between the event and the activation of the script which suggests that if it is possible it will be by a considerably more circuitous route!
-
Jun 30th, 2012, 04:12 PM
#3
Thread Starter
Junior Member
Re: How do I click a javascript button?
These are the only two ways I know of using to click a button inside the web browser:
Code:
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("value") = "Next" Then
webpageelement.InvokeMember("click")
End If
Next
AND
Code:
WebBrowser1.Document.GetElementById("NAME").InvokeMember("click")
Either one will not work.
I dream in VB...
Do
If Sun > 0 Then
Sun.Visible = False
Conscious.Enabled = False
End If
Loop
-
Jun 30th, 2012, 05:34 PM
#4
Re: How do I click a javascript button?
Ok. Now I don't want you getting all excited too soon so let me say right away that I haven't tested this on an element with javascript:void() (largely cos I couldn't actually find one!) nor on every type of element but this definitely works on some pages .... and it's so bleeding obvious that I can't believe I never tried it before! Instead of
webpageelement.InvokeMember("click")
or
WebBrowser1.Document.GetElementById("NAME").InvokeMember("click")
try
webpageelement.InvokeMember("onclick")
or
WebBrowser1.Document.GetElementById("NAME").InvokeMember("onclick")
-
Jun 30th, 2012, 05:39 PM
#5
Thread Starter
Junior Member
Re: How do I click a javascript button?
Dunfiddlin, thank you very much for your time. I will try your two suggestions today and post back again to say my outcome.
Thanks
I dream in VB...
Do
If Sun > 0 Then
Sun.Visible = False
Conscious.Enabled = False
End If
Loop
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|