Sunday, March 27, 2011

Testing checkbox click

I have started testing my UI using qUnit, so I need to simulate some user interaction. Is it possible to "simulate" a user clicking a checkbox using javascript ?

From stackoverflow
  • You can look at this:

    Simulate a buttonclick via javascript

    It is the other way arround, so i'm not sure if it works on checkboxes too.

    TStamper : That is the exact answer I have
  • Yes, take a look at SeleniumIDE. Very good for automated acceptance testing.

  • Thx guyes. I figured it out about two seconds after I posted the question. It was as you say simpler than I had imagined

    document.getElementById('cb1').click();
    

    did the trick

    Edit: It seems in IE7 (and perhaps other browsers) the the click method will not actually check the checkbox. So to fully simulate you need to "check" the checkbox before clicking it

    document.getElementById('cb1').checked=true
    document.getElementById('cb1').click();
    

0 comments:

Post a Comment