How to select an option from dropdown select

Metropolis picture Metropolis · Aug 24, 2017 · Viewed 58.5k times · Source

I can click the selector but my question is how to select one of the options from the dropdown list?

await page.click('#telCountryInput > option:nth-child(4)')

Click the option using CSS selector does not work.

For example, select a country code from a list like below:

screenshot of the select element

Answer

zaboco picture zaboco · Nov 22, 2017

Puppeteer v0.13.0 has page.select() method, which does exactly that. You just have to give it the value to select. So, assuming you have an <option value="my-value"> in your <select>:

await page.select('#telCountryInput', 'my-value')