How to select an element in protractor having multiple classes?

Jyotirmoy Pan picture Jyotirmoy Pan · Jan 20, 2015 · Viewed 30.6k times · Source

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

Answer

Andres D picture Andres D · Jan 20, 2015

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'))