How to set value of select with node Puppeteer
I found a solution myself:
async function setSelectVal(sel, val) {
page.evaluate((data) => {
return document.querySelector(data.sel).value = data.val
}, {sel, val})
}
await setSelectVal('#select_id', 'newValue')
You can use page.select()
to select
an option
:
await page.select('select#example', 'carrot');