使用操纵符更改属性的值 [英] changing the value of attributes using puppeteer

查看:40
本文介绍了使用操纵符更改属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元素"input [name = startdate]",属性为"value ="2018-06-20""

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?

类似...

让newDate ='2018-01-01'

let newDate = '2018-01-01'

value.innerHTML = newDate

value.innerHTML = newDate

推荐答案

我能够弄清楚它,如果有其他人遇到同样的问题,我会在这里发布.

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

这篇关于使用操纵符更改属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆