Currently I am delving into the realm of protractor and typescript while engaged in creating an automation test suite utilizing these technologies.
I formulated a method as:
private allElements = $$('.some-list li');
public async getDateElement(calDate: string) {
this.allElements.each(async function(element, index){
let eDate = await element.$('p').getText();
if( eDate === calDate){
// I tried both these options
return eDate // getting undefined value here
return element.$('p').click(); // element get clicked but not coming out of loop
}
});
}
Attempting another approach using a for loop, however, encountering issues with the break keyword:
public async getDateElement(calDate: string) {
for (let element of await this.allElements) {
let eDate = await element.$('p').getText();
if (eDate === calDate) {
element.$('p').click();
break;
}
}
}
Struggling to find a way to exit the for loop or return a result. Researching solutions led me to consider incorporating a try-catch block and throwing an exception upon finding matching dates. Is that the sole viable solution? Any assistance provided utilizing promises would be greatly appreciated :)
If further information is necessary, kindly inform me.