Advertisement
Guest User

Untitled

a guest
May 25th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. async function selectByIndex(selector, idx) {
  2. await page.$eval(selector, (element, idx) => {
  3. let _c = 0;
  4. for (const option of Array.from(element.options)) {
  5. console.log(_c, idx, option);
  6.  
  7. if (idx === _c) {
  8. option.selected = true;
  9. element.dispatchEvent(new Event('input', { 'bubbles': true }));
  10. element.dispatchEvent(new Event('change', { 'bubbles': true }));
  11. return true;
  12. }
  13.  
  14. _c++;
  15. }
  16. return false;
  17. }, idx);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement