playwright-fluent
Version:
Fluent API around playwright
30 lines (29 loc) • 951 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllOptionsOfHandle = void 0;
async function getAllOptionsOfHandle(selector, name) {
if (!selector) {
return [];
}
const stringifiedResult = await selector.evaluate((el) => {
const selectElement = el;
if (!selectElement.options) {
return null;
}
const options = Array.from(selectElement.options);
const infos = options.map((option) => {
return {
value: option.value,
label: option.label,
selected: option.selected,
};
});
return JSON.stringify(infos);
});
if (stringifiedResult === null) {
throw new Error(`Cannot find any options in selector '${name}'`);
}
const result = JSON.parse(stringifiedResult);
return result;
}
exports.getAllOptionsOfHandle = getAllOptionsOfHandle;
;