Protractor: Print off first five <li> entries contained inside <ul> element

I have a <ul> div that contains various <li> entries. I would like, to print off just the first five <li> elements and also would like to print them off individually if possible.

This is the css

<ul class="legend-numbers">
<li>-</li>
<li>-</li>
<li>-</li>
<li>58,983.58</li>
<li>127,4563.09</li>
<li>450,918.28</li>
<li>246,833.09</li>
<li>550,953.58</li>
<li>277,733.09</li>i>
<!--anchor-->
			</ul>

And this how I’m trying to tackle this in my page object file

checkFigures (figures) {
	browser.sleep(8000);
   	var balance = element.all(by.css('ul.legend-numbers> li'));
	var cellTexts = balance.map(function (elm) {
    	return elm.getText().then(function (text) {
      	console.log(text);
		});
	    });
	}
 }

I’m not really sure how I only get the first five entries or how I can choose to print off the second <li> element or third <li> element etc. I’ve tried to use indexOf() or .getFirst() but I get errors when I try to do so.
Thanks


Source: stackoverflow-javascript

How to return a list of available options in a select element in Protractor?

I am trying to retrieve all the options available in select element using Protractor. I am having trouble figuring out how to do this because I’m a JavaScript beginner and therefore am having trouble determining how to return the array and not a promise.

I’ve tried this:

getOptions = function () {
    var self = this;
    var availableOptions = [];

    return this.selector.click().then(function () {
        self.selectorOptions.then(function (options) {
            options.forEach(function (option) {
                option.getAttribute("value").then(function (value) {
                    availableOptions.push(value);
                });
            });
        });
    }).then(function () {
        return availableOptions;
    });
};

This returns a promise and not the array which I want. I also tried this:

getOptions = function () {
    var self = this;
    var availableOptions = [];

    this.selector.click().then(function () {
        self.cloudletTypeOptions.then(function (options) {
            options.forEach(function (option) {
                option.getAttribute("value").then(function (value) {
                  availableOptions.push(value);
                });
            });
        });
    });

    return availableOptions;
};

When I do this and call the method from a test and try to print the result, it is ‘undefined’. What do I need to do to ensure that the return value is defined and is an array? Barring that, how do I force the promise to resolve?


Source: stackoverflow-javascript