我正在编写 Appium (v1.7.1) iOS 自动化测试,我在其中链接 webdriver 会话并尝试循环遍历元素以获取数据。
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
循环迭代但不执行 for 循环内的链。有没有办法让链在返回之前完成所有回调执行。