The button you're trying to click isn't a link (or isn't classified as a link), so it isn't in the links collection. Try using the
ahk web recorder (from
this thread), once the recorder is open hold down the control button and hover the mouse over the button you're trying to click. You'll see that the tag type is 'button', so it would be in the button collection. You access the button collection slightly differently then you do the links collection:
Code:
COM_Invoke(pWin,"document.links.length") ; retrieves the number of link items
COM_Invoke(pWin,"document.all.tags[button].length") ; retrieves the number of button items
In the web recorder you'll also see in the Value/InnerText box that it says 'Free Download', so now we know the tag type of the button and the specific text of the button, so we can create a loop that will check all of the button items for one with the innerText 'Free Download':
Code:
Loop % COM_Invoke(pWin,"document.all.tags[button].length") { ; loop will only run for the amount of button items on the page
if InStr(COM_Invoke(pWin,"document.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
{
COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
break ; stop searching
}
}
But that's not the end of it. If you check the OuterHTML box for the button you'll also notice that it contains a statement to the effect of '
onclick=....'; 'onclick' is a JavaScript event that is supposed to fire when the button is clicked, but our method may bypass that event and prevent the click from working properly. Luckily we can make that event occur manually:
Code:
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
{
COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
break
}
}
So with a touch of code tidying:
Code:
url:="http://uploading.com/files/get/1JM4429T/"
IID_IHTMLWindow2:="{332C4427-26CB-11D0-B483-00C04FD90119}"
COM_Init()
pwb:=COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "True")
COM_Invoke(pwb, "Navigate", url)
loop
if COM_Invoke(pwb,"readyState") = 4
break
pWin:=COM_QueryService(pwb,IID_IHTMLWindow2, IID_IHTMLWindow2)
Loop % COM_Invoke(pWin,"document.all.tags[button].length") {
if InStr(COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].innerText"),"Free Download")
{
COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].click")
COM_Invoke(pWin,"document.all.tags[button].item[" A_Index-1 "].fireEvent","onclick")
break
}
}
Sleep 1000
Loop
if COM_Invoke(pwb,"readyState") = 4
break
I believe that should work to click the 'Free Download' link.