Get Elements From Page.evaluate In Puppeteer?
I'm working with Node.js and Puppeteer for the first time and can't find a way to output values from page.evaluate to the outer scope. My algorithm: Login Open URL Get ul Loop ove
Solution 1:
The function page.evaluate() can only return a serializable value, so it is not possible to return an element or NodeList back from the page environment using this method.
You can use page.$$() instead to obtain an ElementHandle array:
const nodes = await page.$$(`${selector} > *`); // selector children
If the length of the constant nodes is 0, then make sure you are waiting for the element specified by the selector to be added to the DOM with page.waitForSelector():
await page.waitForSelector(selector);
Solution 2:
let elementsHendles = await page.evaluateHandle(() => document.querySelectorAll('a'));
let elements = await elementsHendles.getProperties();
let elements_arr = Array.from(elements.values());
Solution 3:
Use page.evaluateHandle()
An API is : here
Post a Comment for "Get Elements From Page.evaluate In Puppeteer?"