Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function selectByIndex(selector, idx) {
- await page.$eval(selector, (element, idx) => {
- let _c = 0;
- for (const option of Array.from(element.options)) {
- console.log(_c, idx, option);
- if (idx === _c) {
- option.selected = true;
- element.dispatchEvent(new Event('input', { 'bubbles': true }));
- element.dispatchEvent(new Event('change', { 'bubbles': true }));
- return true;
- }
- _c++;
- }
- return false;
- }, idx);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement