admin管理员组文章数量:1323323
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?
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?
Share asked Oct 22, 2020 at 16:42 PetranPetran 8,09723 gold badges72 silver badges112 bronze badges 1- Was exactly is your error? Can you share it? – Łukasz Karczewski Commented Oct 22, 2020 at 16:59
1 Answer
Reset to default 7Use 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');
本文标签: javascriptChange element style dynamically with puppeteerStack Overflow
版权声明:本文标题:javascript - Change element style dynamically with puppeteer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742140468a2422559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论