Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/injected/src/injectedScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,18 @@ export class InjectedScript {
let remainingOptionsToSelect = optionsToSelect.slice();
for (let index = 0; index < options.length; index++) {
const option = options[index];
const normalizedOptionLabel = normalizeWhiteSpace(option.label);
const filter = (optionToSelect: Node | { valueOrLabel?: string, value?: string, label?: string, index?: number }) => {
if (optionToSelect instanceof Node)
return option === optionToSelect;
const matchesLabel = (label: string) => label === option.label || normalizeWhiteSpace(label) === normalizedOptionLabel;
let matches = true;
if (optionToSelect.valueOrLabel !== undefined)
matches = matches && (optionToSelect.valueOrLabel === option.value || optionToSelect.valueOrLabel === option.label);
matches = matches && (optionToSelect.valueOrLabel === option.value || matchesLabel(optionToSelect.valueOrLabel));
if (optionToSelect.value !== undefined)
matches = matches && optionToSelect.value === option.value;
if (optionToSelect.label !== undefined)
matches = matches && optionToSelect.label === option.label;
matches = matches && matchesLabel(optionToSelect.label);
if (optionToSelect.index !== undefined)
matches = matches && optionToSelect.index === index;
return matches;
Expand Down
11 changes: 11 additions & 0 deletions tests/page/page-select-option.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ it('should select single option by label', async ({ page, server }) => {
expect(await page.evaluate(() => window['result'].onChange)).toEqual(['indigo']);
});

it('should select single option by label with html whitespace', async ({ page }) => {
await page.setContent(`
<select>
<option value="plain">Plain</option>
<option value="html">&nbsp;HTML</option>
</select>
`);
await page.selectOption('select', { label: 'HTML' });
expect(await page.evaluate(() => document.querySelector('select').value)).toBe('html');
});

it('should select single option by handle', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/select.html');
await page.selectOption('select', await page.$('[id=whiteOption]'));
Expand Down
Loading