peetyp
peetyp

Reputation: 175

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

Upvotes: 4

Views: 11300

Answers (1)

peetyp
peetyp

Reputation: 175

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
    )}

Upvotes: 12

Related Questions