Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29129

Protractor: Compare two element for equality

I have this list of elements

list = element.all(by.css(....));

One of them has an specific attribute

specific = list.element(by.css('[active]');

Now I would like to check if this specific element is the first

expect(list.get(0)).toBe(specific)

However this doesn't work (it doesn't match). Any suggestion how to compare elements?

Upvotes: 1

Views: 1925

Answers (1)

alecxe
alecxe

Reputation: 473853

You can get the value of active attribute and see if it is not null:

expect(list.first().getAttribute("active")).not.toBeNull();

You cannot though directly compare elements, but, you can compare ids or outerHTML attribute values of elements:

expect(list.first().getId()).toEqual(specific.id());
expect(list.first().getAttribute("outerHTML")).toEqual(specific.getAttribute("outerHTML"));

Upvotes: 4

Related Questions