0

I am trying to click a download and a graph link on a webpage and I can not seem to get it to work.

Everything I've worked with so far seems to have an ID/Name/Class that work well with getElementById/Name call, but with this link I cant seem to find anything that will reference to it and click. Please, help me!

CODE:

<.a href="#" onclick="spr_command('plot_graph'); return false;">Graph</a>
<.a href="#" onclick="spr_command('download'); return false;">Download</a>
SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Mres
  • 21
  • 1
  • 9
  • you need to execute the JS. Try this: http://stackoverflow.com/questions/3247391/click-button-or-execute-javascript-function-with-vba – cyboashu Jun 28 '16 at 14:48
  • Thanks very much! It works well. You made my day. – Mres Jun 28 '16 at 15:47
  • @cyboashu How should I write the script to execute this following method `code ` – Mres Jun 29 '16 at 15:31
  • I tried `code Dim CurrentWindow As HTMLWindowProxy Set CurrentWindow = ie.Document.parentWindow Call CurrentWindow.execScript("var dl_var = find_control('download')") ` but it is not working – Mres Jun 29 '16 at 15:33

3 Answers3

1

Thanks for you comment cyboashu!

It works pretty well!

The solution is:

Dim CurrentWindow As HTMLWindowProxy 
Set CurrentWindow = ie.Document.parentWindow
Call CurrentWindow.execScript("spr_command('plot_graph')")
Mres
  • 21
  • 1
  • 9
0

Have you tried getElementsByTagName("a")? and the FireEvent('OnClick')

Nathan_Sav
  • 8,466
  • 2
  • 13
  • 20
  • You mean: Set Element = .document.getElementsTagName("spr_command('plot_graph')")(0) Element.FireEvent ("onclick") – Mres Jun 28 '16 at 15:30
  • no, document.getElementsByTagName("a"), then you'll need to look through them for their innerText/innerHTML to be "download" spr_command is the function called on click – Nathan_Sav Jun 28 '16 at 15:34
  • Thanks for you colaboration! I found the solution. – Mres Jun 28 '16 at 15:54
0

a simple javascript will do.

window.spr_command = function(action){
   alert(action);
}
<a href="#" onclick="spr_command('plot_graph'); return false;">Graph <br />

<a href="#" onclick="spr_command('download'); return false;">Download
Allan Empalmado
  • 943
  • 1
  • 6
  • 12