I am writing Appium (v1.7.1) iOS automation tests where I am chaining a webdriver session and trying loop through the elements to fetch the data.
setFilterOptions: function (driver, loc) {
var chain = driver; //I am assigning the driver to chain
chain = chain
.getFilterElementListCount() //This gives me back the count for elements
.then((count) => {
console.log("Number of Filters - ",count);
for(var i=1; i<=count; i++) {
((i) => {
console.log("Value of i - ", i);
//This gives me the label for each Cell->StaticText
chain = chain
.getElAttribute('label',util.format('//XCUIElementTypeCell[%d]/XCUIElementTypeStaticText[1]', i), 'xpath')
.then((filterTitle, i) => {
console.log("Filter Title - ", filterTitle);
console.log("I value - ", i);
});
})(i);
}
});
return chain;
},
The Console o/p i am getting is -
Number of Filters - 3
Value of i - 1
Value of i - 2
Value of i - 3
The loop iterates but doesn't execute the chain within the for loop. Is there a way for the chain to finish all callback execution before returning it.