Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
});
like image 557
Jyotirmoy Pan Avatar asked Jan 20 '15 11:01

Jyotirmoy Pan


2 Answers

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'))
like image 156
Andres D Avatar answered Oct 15 '22 01:10

Andres D


Try replace class2 to .class2.

like image 36
IProblemFactory Avatar answered Oct 15 '22 02:10

IProblemFactory