Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ async function selectOption(
using childValueHandle = await childHandle.getProperty('value');

const childValue = await childValueHandle.jsonValue();
if (childValue) {
await handle.asLocator().fill(childValue.toString());
if (typeof childValue === 'string') {
await handle.asLocator().fill(childValue);
}

break;
Expand Down
38 changes: 38 additions & 0 deletions tests/tools/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,44 @@ describe('input', () => {
});
});

it('fills out a select option with an empty value by text', async () => {
await withMcpContext(async (response, context) => {
const page = context.getSelectedMcpPage().pptrPage;
await page.setContent(
html`<select
><option value="">none</option
><option
value="v2"
selected
>two</option
></select
>`,
);
context.getSelectedMcpPage().textSnapshot = await TextSnapshot.create(
context.getSelectedMcpPage(),
);
await fill.handler(
{
params: {
uid: '1_1',
value: 'none',
},
page: context.getSelectedMcpPage(),
},
response,
context,
);
assert.strictEqual(
response.responseLines[0],
'Successfully filled out the element',
);
const selectedValue = await page.evaluate(
() => document.querySelector('select')!.value,
);
assert.strictEqual(selectedValue, '');
});
});

it('fills out a textarea marked as combobox', async () => {
await withMcpContext(async (response, context) => {
const page = context.getSelectedMcpPage().pptrPage;
Expand Down
Loading