Search code examples
angularjstestingjasmineprotractorend-to-end

How to select an element in protractor having multiple classes?


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();
});

Solution

  • Try replace class2 to .class2.