UNPKG

@hyperbrowser/agent

Version:

Hyperbrowsers Web Agent

33 lines (32 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelectOptionActionDefinition = exports.SelectOptionAction = void 0; const zod_1 = require("zod"); const utils_1 = require("./utils"); exports.SelectOptionAction = zod_1.z .object({ index: zod_1.z .number() .describe("The numeric index of the element to select an option."), text: zod_1.z.string().describe("The text of the option to select."), }) .describe("Select an option from a dropdown element"); exports.SelectOptionActionDefinition = { type: "selectOption", actionParams: exports.SelectOptionAction, run: async (ctx, action) => { const { index, text } = action; const locator = (0, utils_1.getLocator)(ctx, index); if (!locator) { return { success: false, message: "Element not found" }; } await locator.selectOption({ label: text }); return { success: true, message: `Selected option "${text}" from element with index ${index}`, }; }, pprintAction: function (params) { return `Select option "${params.text}" from element at index ${params.index}`; }, };