Tom Sandmann Tom Sandmann - 1 month ago 11x
AngularJS Question

getText() on items ng-repeat returns empty string

Currently our team is writing tests using Protractor for our software project written in AngularJS.
For a specific test, we have to retrieve the values from a dropdown button to see if a previous saved value has actually been saved.

The code is as follows:

this.Then(/^the profile is saved under the name (.*)$/, function (presetName, callback) {
element.all(by.repeater('preset in dropDown.presets')).each(function(element, index){
console.log("Index: ", index);
console.log("Text of element: ", name); //name is empty string
callback("Error, presetName was not found!");

The corresponding HTML:

<div class="btn-group" uib-dropdown>
<button id="presetList" type="button" class="btn btn-primary" uib-dropdown-toggle
style="min-width:100px" ng-disabled="presets.length == 0">
{{dropDown.selected ? dropDown.selected : ('PRESETS.SELECT_TEXT' | translate)}}
<span class="caret"></span>
<ul uib-dropdown-menu role="menu" class="listOfPresets">
<li role="menuitem" ng-repeat="preset in dropDown.presets">
<a href ng-click="setSelected(preset)">

As we have already seen in previous posts (here), this does not work.
We have tried
but this does not work either, although this is suggested on the FAQ.
We know for sure the element is there (count prints 1), and we can even see the element after the test ends, but we are still having problems retrieving the names for those entries.

Any help is appreciated!


It seems like you first have to open the dropdown before you can retrieve any values. This fixed our problem. The final code in Protractor:

    this.Then(/^the profile is saved under the name (.*)$/, function (presetName, callback) {
            var presetOptions = element.all('presetOption'));
            var presetNames = presetOptions
                .map(function (preset, index) {
                    return preset.getText();