Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the value of attributes using puppeteer

I have an element 'input[name=startdate]' with an attribute 'value="2018-06-20"' instead of using puppeteer to interact with the calendar that is used to change the date, is there anyway I can use puppeteer to set the value instead?

something like...

let newDate = '2018-01-01'

value.innerHTML = newDate

like image 339
peetyp Avatar asked Jan 02 '23 05:01

peetyp


1 Answers

I was able to figure it out and I'm posting it here in case anyone else has the same problem.

await page.$eval('input[name=startdate]', e => e.setAttribute("value", "2018-01-01"))

If you want to set the date as a variable...

const randomDate = '2018-01-01'
await page.$eval('input[name=startdate]', (e, randomDate) => { 
    e.setAttribute("value", randomDate),
    randomDate
    )}
like image 165
peetyp Avatar answered Jan 05 '23 19:01

peetyp