简体   繁体   中英

Using puppeteer to access react event handlers

I am trying to use puppeteer to access properties of an element. Specifically I need the key or listingId from the react event handler object

__reactEventHandlers$(the rest is dynamically generated) > children[0] > key

screenshot from devtools on page元素 .RoyalTicketList__container 上的属性选项卡

So far await page.$(".RoyalTicketListPanel"); or await page.$(".RoyalTicketListPanel__0"); the first being a ul element and the second being the first list item, returns a lot of data for the element, but not the event handler object.
I've tried

await page.evaluate((selector) => {
    return document.querySelector(selector);
}, selector);

as well and it just returns undefined.
Someone posted a similar question here How to access React Event Handlers with Puppeteer
But the answer also returns undefined in my case.
I'm stumped at this point, if anyone can help me out with this it would be greatly appreciated.
Also, if anyone wants to try to recreate what I'm doing, I'm using puppeteer to go to an event on stubhub then trying to get the ticket's listing ids from the ticket list.

var abc=document.querySelector('.RoyalTicketListPanel');
var reactHandlerKey=Object.keys(abc).filter(function(item){
   return item.indexOf('__reactEventHandlers')>=0
});
var reactHandler=abc[reactHandlerKey[0]];
console.log(reactHandler);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM