When using page.$$eval()
, you can obtain the length
of the elements in question with:
const curLiveScoreElements = await page.$$eval( scoreSelector, ele => ele.length );
console.log( curLiveScoreElements );
You can also use page.$$()
to obtain an ElementHandle
array, like you mentioned, in which you can log the length of the result:
const curLiveScoreElements = await page.$$( scoreSelector );
console.log( curLiveScoreElements.length );
Alternatively, you can listen for the 'console'
event to happen within the page, and display the results:
page.on( 'console', msg => {
for ( let i = 0; i < msg.args().length; i++ ) {
console.log( `${i}: ${msg.args()[i]}` );
}
});
const curLiveScoreElements = await page.$$( scoreSelector );
await page.evaluate( ele => { console.log( ele.length ); }, curLiveScoreElements );