node.js - How to set value of select with node Puppeteer -


i trying automation rather new googlechrome/puppeteer library, cannot figure out how set value in select field.

here (simplified) function set value of text input:

async function setinputval(sel, text) {     await page.focus(sel)             page.press('backspace')     page.type(text) }  await setinputval('input.searchjob', task.id) 

i cant figure out how same select field.

i have tried set focus, insert script , execute cannot working.

i found 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') 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -