0

I am new to javascript and casperjs.I am trying to trigger a button for automating a specific task. I can do it by clicklabel(). I would like to know if there is direct way to call those functions. There is a sendAJAX function in casperjs documentation. Does it work in this case?

<a class="selection" href="javascript:void(0)" onclick="function1(); function2();">New</a>
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
feminkk
  • 1,135
  • 2
  • 14
  • 18

1 Answers1

1

You don't actually need the href in this case - just leave it blank.

For an answer to your question, however, there look to be two options. The first, and best overall, is the jQuery .click() function. jQuery is awesome, and if you're doing stuff with javascript, you owe it to yourself to learn (though it does take a little while to learn how to use it properly). If you're not willing to take that time at the moment, however, I suggest How to simulate a click with JavaScript? as looking like a workable javascript-only answer.

Community
  • 1
  • 1
Ben Barden
  • 2,001
  • 2
  • 20
  • 28
  • when i do document.getElementsByClassName('selection')[0].click() ,It shows error :undefined – feminkk Mar 14 '13 at 17:50
  • I apologize. I trusted the accuracy of w3schools. I should not have done that. Please find the corrected and somewhat more thorough answer above (including link). – Ben Barden Mar 14 '13 at 19:46
  • you were right.i just missed one parameter for my function.Thanks a lot – feminkk Mar 15 '13 at 07:56