Chrome DevTools for coding agents
fix(input): select empty-value options by text (#2501)
s4kurab969c45c657a
diff --git a/src/tools/input.ts b/src/tools/input.tsindex 7a05acb1..a67a2013 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.tsindex 80559143..5bd0c788 100644--- a/tests/tools/input.test.ts+++ b/tests/tools/input.test.ts@@ -589,6 +589,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;