browser_scroll_to_element
Scrolls the browser viewport to locate and bring web elements into view using locator strategies like ID, CSS, or XPath for automated testing and interaction.
Instructions
Scroll to an element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| by | Yes | Locator strategy to find element | |
| value | Yes | Value for the locator strategy | |
| timeout | No | Maximum time to wait for element in milliseconds |
Implementation Reference
- src/services/actionService.ts:69-73 (handler)Core implementation of scrolling to the element using Selenium WebDriver: locates the element and executes JavaScript 'scrollIntoView()'.async scrollToElement(params: LocatorParams): Promise<void> { const locator = LocatorFactory.createLocator(params.by, params.value); const element = await this.driver.wait(until.elementLocated(locator), params.timeout || 15000); await this.driver.executeScript('arguments[0].scrollIntoView();', element); }
- src/tools/actionTools.ts:257-280 (registration)Registers the MCP tool 'browser_scroll_to_element' with input schema based on locatorSchema and a handler that delegates to ActionService.scrollToElement.server.tool( 'browser_scroll_to_element', 'Scroll to an element', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.scrollToElement({ by, value, timeout }); return { content: [{ type: 'text', text: `Scrolled to element` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error scrolling to element: ${(e as Error).message}`, }, ], }; } } );
- src/types/index.ts:29-35 (schema)Zod schema defining the input parameters for element locators: 'by' (strategy), 'value', and optional 'timeout'.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'), };