mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-11-04 15:00:11 +00:00
fix: check that combobox is actually a select element before filling out options (#979)
Closes https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/975
This commit is contained in:
1 parent
c0009f7ab2
commit
d2bc489e43
2 files changed
+36
-3
No files matched your search
+7
-1
@@ -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,
|
||||
@@ -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.
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in new issue
Block a user