Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set values of DOM elements with puppeteer?

How to set specific values of the DOM with Puppeteer?

i.e:

b = document.querySelector("button");

  • b.innerHTML = 'value';
  • b.setAttribute('specific-attr', 'value');
like image 570
Slake Avatar asked Oct 16 '25 14:10

Slake


1 Answers

For the innerHTML:

await page.evaluate(() => document.querySelector('button').innerHTML = 'value');

For the specific attribute:

await page.evaluate(() => document.querySelector('button').setAttribute('specific-attr', 'value'));

like image 180
Slake Avatar answered Oct 18 '25 08:10

Slake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!