changing the value of attributes using puppeteer

前提是你 提交于 2021-02-16 09:15:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!