browser_element_is_selected
Check if a web element is selected using Selenium WebDriver. Specify locator strategy and value to verify selection state for testing and automation.
Instructions
Checks if an element is selected
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/tools/elementTools.ts:265-292 (registration)Registers the 'browser_element_is_selected' MCP tool, providing the schema and a thin async handler that instantiates ElementService and calls its isElementSelected method, returning formatted text response.server.tool( 'browser_element_is_selected', 'Checks if an element is selected', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); const isSelected = await elementService.isElementSelected({ by, value, timeout, }); return { content: [{ type: 'text', text: `Element is selected: ${isSelected}` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error checking element selected status: ${(e as Error).message}`, }, ], }; } } );
- src/services/elementService.ts:68-75 (helper)Core helper method in ElementService that finds the element using locator params and checks if it is selected via Selenium WebElement.isSelected(), returning false on error.async isElementSelected(params: LocatorParams): Promise<boolean> { try { const element = await this.findElement(params); return element.isSelected(); } catch { return false; } }
- src/types/index.ts:29-35 (schema)Zod schema defining the input parameters for element locators (by, value, optional timeout), used by the tool.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'), };