feat(tool): add locator.selectOption() action (#25)

Implemented `locator.selectOption`
This commit is contained in:
ryo kishida
2025-03-26 13:53:56 +09:00
committed by GitHub
parent 8f3214a06a
commit 9f93af3a81
4 changed files with 132 additions and 0 deletions

View File

@@ -112,6 +112,26 @@ export const type: Tool = {
},
};
const selectOptionSchema = elementSchema.extend({
values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
});
export const selectOption: Tool = {
schema: {
name: 'browser_select_option',
description: 'Select an option in a dropdown',
inputSchema: zodToJsonSchema(selectOptionSchema),
},
handle: async (context, params) => {
const validatedParams = selectOptionSchema.parse(params);
return await runAndWait(context, `Selected option in "${validatedParams.element}"`, async page => {
const locator = refLocator(page, validatedParams.ref);
await locator.selectOption(validatedParams.values);
}, true);
},
};
function refLocator(page: playwright.Page, ref: string): playwright.Locator {
return page.locator(`aria-ref=${ref}`);
}