How to select a single item in protractor

user2167582 picture user2167582 · Nov 26, 2013 · Viewed 39.9k times · Source

Usually in protractor you can select singular element with:

element(protractor.By.css('#fdfdf'));

Occasionally you get something like this:

element(protractor.By.css('.dfdf'));

which potentially has more than one element. What's the correct way to select an index from a locator that locates multiple elements, and still contain the protractor's methods for sending Keys?

Answer

Jmr picture Jmr · Dec 4, 2013

You can get an indexed element from an array returned with

// Get the 5th element matching the .dfdf css selector
element.all(by.css('.dfdf')).get(4).sendKeys('foo');