browser_element_is_displayed
Check if a web element is visible on the page using locator strategies like ID, CSS, or XPath to verify element display status for automated testing.
Instructions
Checks if an element is displayed
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/elementTools.ts:207-234 (registration)Registration of the 'browser_element_is_displayed' tool, including inline handler function that uses ElementService to check if the element is displayed.server.tool( 'browser_element_is_displayed', 'Checks if an element is displayed', { ...locatorSchema }, async ({ by, value, timeout = 15000 }) => { try { const driver = stateManager.getDriver(); const elementService = new ElementService(driver); const isDisplayed = await elementService.isElementDisplayed({ by, value, timeout, }); return { content: [{ type: 'text', text: `Element is displayed: ${isDisplayed}` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error checking element display status: ${(e as Error).message}`, }, ], }; } } );
- src/services/elementService.ts:50-57 (handler)Core handler logic in ElementService.isElementDisplayed: waits for element, calls Selenium's isDisplayed() on it, returns false on error.async isElementDisplayed(params: LocatorParams): Promise<boolean> { try { const element = await this.findElement(params); return element.isDisplayed(); } catch { return false; } }
- src/types/index.ts:29-35 (schema)locatorSchema defines the input parameters (by, value, 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'), };
- src/services/elementService.ts:8-11 (helper)findElement helper method used by isElementDisplayed to locate the element using LocatorFactory.async findElement(params: LocatorParams): Promise<WebElement> { const locator = LocatorFactory.createLocator(params.by, params.value); return this.driver.wait(until.elementLocated(locator), params.timeout || 15000); }