问题
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
回答1:
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
)}
来源:https://stackoverflow.com/questions/50951616/changing-the-value-of-attributes-using-puppeteer