17

I have a div like this:

<div class="class1 class2 class3" ng-click="displayItems(category.categoryId, category.categoryDescription, category.associatedToElements, 'isItemChecked')"> </div>

When I am trying to get the element in Protractor by css:

var elementList =  element.all(by.css('class2'));

I am getting undefined.

When I am trying the same with ng-click:

var elementList = element.all(by.css('[ng-click="displayItems(category.categoryId, category.categoryDescription, category.associatedToElements, "isItemChecked")"]'))

still I am unable to track any element.

Suggestions are most welcome.

This is my code:

var categoryList, firstCategory;
beforeEach(function(){
    categoryList = element.all(by.css('.class2'));
    firstCategory = categoryList.last();
});

it('Should display values correctly', function(){
    firstCategory.click();
});
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Jyotirmoy Pan
  • 837
  • 2
  • 10
  • 28

2 Answers2

33

If you are learning how to use protractor I would suggest you to try elementor. It will suggest selectors based on the currently selected item.

You can do this:

$('.class1.class2.class3')

It is the same as:

element(by.css('.class1.class2.class3'))
Andres D
  • 8,910
  • 2
  • 26
  • 31
13

Try replace class2 to .class2.

IProblemFactory
  • 9,551
  • 8
  • 50
  • 66