diff --git a/src/tools/input.ts b/src/tools/input.ts index 7a05acb171..a67a20131f 100644 --- a/src/tools/input.ts +++ b/src/tools/input.ts @@ -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; diff --git a/tests/tools/input.test.ts b/tests/tools/input.test.ts index eaa8445bc4..0611a2c59b 100644 --- a/tests/tools/input.test.ts +++ b/tests/tools/input.test.ts @@ -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``, + ); + 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;