OrdinaryKing
OrdinaryKing

Reputation: 461

Playwright SelectOption is not selecting a value

When attempting to use page.SelectOption with Playwright, im getting an issue where my chosen value is not being selected, it doesnt matter if I use index, value, or label to try to select.

I know the selector is being found as when I debug using trace viewer I cant see that the step shows: enter image description here

However on the select box it doesn't change and acts like it hasn't selected anything.

enter image description here

code used: await page.selectOption('#select', "2");

Upvotes: 5

Views: 10828

Answers (3)

Vishal Aggarwal
Vishal Aggarwal

Reputation: 4199

'$' is deprecated ,use locator based select option:

await page.locator('#select').selectOption('1')

Upvotes: 0

Lakhan
Lakhan

Reputation: 1

Before selecting an option, make a call for wait_for_timeout. simply..

page.wait_for_timeout(3_000)

Hope, this helps

Upvotes: -1

OrdinaryKing
OrdinaryKing

Reputation: 461

Another way of doing the above is:

const selector = await page.$("#select")

await selector?.selectOption("2")

However the original did work for me, there seems to be a bug with traceviewer where the after shot does not show the selected option. Github issue raised:

https://github.com/microsoft/playwright/issues/9212

Upvotes: 3

Related Questions