I would like to store all labels from a drop-down list in a variable and compare with another variable thanks to WEBDRIVERIO.
I tried this but it’s failing:
// Locate the select element
const selectElement = await $('//select[@name="myDropDown"]');
const optionTexts ='';
selectElement.forEach((element) => {
optionTexts = element.getText();
});
I tried this also but it’s not working:
selectElement .map(option => option.getText());
This code is not working too with the error: object is not iterable (cannot read property Symbol(Symbol.iterator)):
const dropdown = await $('//select[@name="fdYearFilter"]');
// Retrieve all the option elements within the drop-down
const options = await dropdown.$$('option');
// Extract the text of each option and store in an array
const optionTexts = await Promise.all(options.map(async (option) => {
return await option.getText();
}));
Could you please help me with that ?
Thanks for your help.