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 #1556

Open
olegbespalov opened this issue Dec 2, 2024 · 0 comments
Open

Support string-labels in locator.selectOption #1556

olegbespalov opened this issue Dec 2, 2024 · 0 comments

Comments

@olegbespalov
Copy link
Contributor

What?

While working on fixing panic from #1415 (PR #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 #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.

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

No branches or pull requests

1 participant