mercredi 5 août 2015

Trigger click programatically on a single element of a list in Angular/JavaScript

I am writing a test where I want to click on say the second item in a list and check that something has changed.

I have a bullet list element:

<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>

I have tried the following (element is the angular element containing the entire list):

var li = element.find('li');

li.triggerHandler('click'); //Clicks all elements
li[1].triggerHandler('click'); //Error: li[1].triggerHandler is not a function

None of these works. The first attempt clicks all items and the second throws an error.

Any ideas how to only trigger click on the second item?

Aucun commentaire:

Enregistrer un commentaire