I am trying to create a method that returns a string of an option in a dropdown selector given the specific index. I want to then call that method and store the string in a variable. Note: calling the function in protractor tests.
Here is my code:
returnStringDropDownValue = function(elementId, index) {
var returnValue;
var options = element(by.id(elementId)).findElements(by.tagName('option'))
.then(function(options){
returnValue = options[index].getText();
});
return returnValue;
};
var x = returnStringDropDownValue('myId' ,1);
Whenever I call this method it returns undefined.I am new to javascript and protractor, can you please help?