browser_submit_form
Automate form submission on web pages by locating form elements using various strategies like ID, CSS, or XPath to complete web interactions programmatically.
Instructions
Submit a form
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| timeout | No | Maximum time to wait for element in milliseconds | |
| value | Yes | Value for the locator strategy |
Implementation Reference
- src/tools/actionTools.ts:418-436 (registration)Registers the 'browser_submit_form' MCP tool, providing its description, input schema based on locatorSchema, and an inline asynchronous handler function that retrieves the WebDriver, instantiates ActionService, calls submitForm on the located form element, and returns success or error messages.server.tool('browser_submit_form', 'Submit a form', { ...locatorSchema }, async ({ by, value }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.submitForm({ by, value }); return { content: [{ type: 'text', text: `Submitted form` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error submitting form: ${(e as Error).message}`, }, ], }; } });
- src/types/index.ts:29-35 (schema)Defines the Zod-based input schema (locatorSchema) used by the browser_submit_form tool for locating the form element via 'by' strategy and 'value'.export const locatorSchema = { by: z .enum(['id', 'css', 'xpath', 'name', 'tag', 'class', 'link', 'partialLink']) .describe('Locator strategy to find element'), value: z.string().describe('Value for the locator strategy'), timeout: z.number().optional().describe('Maximum time to wait for element in milliseconds'), };
- src/services/actionService.ts:91-95 (helper)Core helper method in ActionService that implements form submission: creates a locator, waits for the form element, and invokes Selenium's submit() method on it.async submitForm(params: LocatorParams): Promise<void> { const locator = LocatorFactory.createLocator(params.by, params.value); const form = await this.driver.wait(until.elementLocated(locator), params.timeout || 15000); await form.submit(); }