I am trying to get an element and set its font size with puppeteer
const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
const page = await browser.newPage();
const html = `<html></html><body style="width:2000">
<span class="text">${text}</span>
</body></html>`
await page.setContent(html)
await page.waitForSelector('.text');
let textContent = await page.$('.text')
textContent.style.fontSize = 150 + 'px'
This gives me an error, is it possible to achieve what I am trying to?
Use ElementHandle.evaluate(fn) in this case. So you should do it like this
let textContent = await page.$('.text');
await textContent.evaluate((el) => el.style.fontSize = 150 + 'px');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With