First we need to find the element in the text.
function findElemByText({str, selector = '*', leaf = 'outerHTML'}){
Save it in the same folder as your puppeteer script, name it script.js .
Now we can use this in our puppeteer script. We can use the ElementHandle, but for ease of understanding, I use the .evaluate() function provided by the puppeteer.
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com');
Do not copy paste the code above, try to understand it and enter it yourself. If the code above does not work, try to find out why it does not work.
Md. Abu taher
source share