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
8 changes: 7 additions & 1 deletion src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ async function selectOption(
}
}

function hasOptionChildren(aXNode: TextSnapshotNode) {
return aXNode.children.some(child => child.role === 'option');
}

async function fillFormElement(
uid: string,
value: string,
Expand All @@ -185,7 +189,9 @@ async function fillFormElement(
const handle = await context.getElementByUid(uid);
try {
const aXNode = context.getAXNodeByUid(uid);
if (aXNode && aXNode.role === 'combobox') {
// We assume that combobox needs to be handled as select if it has
// role='combobox' and option children.
if (aXNode && aXNode.role === 'combobox' && hasOptionChildren(aXNode)) {
await selectOption(handle, aXNode, value);
} else {
// Increase timeout for longer input values.
Expand Down
31 changes: 29 additions & 2 deletions tests/tools/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,40 @@ describe('input', () => {
});
});

it('fills out a textarea marked as combobox', async () => {
await withMcpContext(async (response, context) => {
const page = context.getSelectedPage();
await page.setContent(html`<textarea role="combobox" />`);
await context.createTextSnapshot();
await fill.handler(
{
params: {
uid: '1_1',
value: '1',
},
},
response,
context,
);
assert.strictEqual(
response.responseLines[0],
'Successfully filled out the element',
);
assert.ok(response.includeSnapshot);
assert.ok(
await page.evaluate(() => {
return document.body.querySelector('textarea')?.value === '1';
}),
);
});
});

it('fills out a textarea with long text', async () => {
await withMcpContext(async (response, context) => {
const page = context.getSelectedPage();
await page.setContent(html`<textarea />`);
await page.focus('textarea');
await context.createTextSnapshot();
await page.setDefaultTimeout(1000);
page.setDefaultTimeout(1000);
await fill.handler(
{
params: {
Expand Down