Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support string-labels in locator.selectOption #4111

Open
olegbespalov opened this issue Dec 2, 2024 · 1 comment
Open

Support string-labels in locator.selectOption #4111

olegbespalov opened this issue Dec 2, 2024 · 1 comment

Comments

@olegbespalov
Copy link
Contributor

What?

While working on fixing panic from grafana/xk6-browser#1415 (PR grafana/xk6-browser#1552) we figured out that the locator.selectOption also currently doesn't support selecting by label if it's a string input, the cases like:

<select name="numbers" id="numbers-options" multiple>
	<option value="zero">Zero</option>
	<option value="one">One</option>
	<option value="two">Two</option>
	<option value="three">Three</option>
	<option value="four">Four</option>
	<option value="five">Five</option>
</select>
await options.selectOption(['Two', 'Four']); // labels
await options.selectOption('Five'); // label

The playwright does support that https://playwright.dev/docs/api/class-locator#locator-select-option

Workaround

As the workaround for now (if grafana/xk6-browser#1552 merged) you could use object definition, like:

import { browser } from 'k6/browser';

export const options = {
	scenarios: {
		browser: {
			executor: 'shared-iterations',
			options: {
  			   browser: {
  				   type: 'chromium',
  			   },
  			},
		},
	},
};
export default async function () {
	const page = await browser.newPage();
	await page.goto('https://test.k6.io/browser.php');
	const options = page.locator('#numbers-options');

	await options.selectOption([{label:'One'}, {label:'Three'}]); // multiply labels
	await page.screenshot({ path: 'screenshots.png' });
}

Why?

It's expected to also be able to select options by label.

@olegbespalov olegbespalov transferred this issue from grafana/xk6-browser Dec 13, 2024
@navyanihitha
Copy link

Hi @ankur22 , @olegbespalov . Interested to work on this issue, Wanted to check if I could contribute to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants