Skip to main content
Glama

tauri_webview_find_element

Locate DOM elements in Tauri app webviews for UI automation and debugging. Specify selectors to identify elements during testing sessions.

Instructions

[Tauri Apps Only] Find DOM elements in a running Tauri app's webview. Requires active tauri_driver_session. Targets the only connected app, or the default app if multiple are connected. Specify appIdentifier (port or bundle ID) to target a specific app. For browser pages or documentation sites, use Chrome DevTools MCP instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
windowIdNoWindow label to target (defaults to "main")
appIdentifierNoApp port or bundle ID to target. Defaults to the only connected app or the default app if multiple are connected.
selectorYes
strategyNocss

Implementation Reference

  • Core handler function 'findElement' that constructs the script parameters and executes the find-element script in the target Tauri webview window.
    export interface FindElementOptions { selector: string; strategy: string; windowId?: string; appIdentifier?: string | number; } /** * Find an element using various selector strategies. */ export async function findElement(options: FindElementOptions): Promise<string> { const { selector, strategy, windowId, appIdentifier } = options; const script = buildScript(SCRIPTS.findElement, { selector, strategy }); try { return await executeInWebview(script, windowId, appIdentifier); } catch(error: unknown) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Find element failed: ${message}`); } }
  • Zod input schema validation for the tool parameters: selector (string) and strategy (css|xpath|text, default css), extending shared WindowTargetSchema.
    export const FindElementSchema = WindowTargetSchema.extend({ selector: z.string(), strategy: z.enum([ 'css', 'xpath', 'text' ]).default('css'), });
  • Tool registration in the central TOOLS array, defining name, description, category, schema reference, annotations, and thin wrapper handler that parses input and delegates to findElement implementation.
    { name: 'tauri_webview_find_element', description: '[Tauri Apps Only] Find DOM elements in a running Tauri app\'s webview. ' + 'Requires active tauri_driver_session. ' + MULTI_APP_DESC + ' ' + 'For browser pages or documentation sites, use Chrome DevTools MCP instead.', category: TOOL_CATEGORIES.UI_AUTOMATION, schema: FindElementSchema, annotations: { title: 'Find Element in Tauri Webview', readOnlyHint: true, openWorldHint: false, }, handler: async (args) => { const parsed = FindElementSchema.parse(args); return await findElement({ selector: parsed.selector, strategy: parsed.strategy, windowId: parsed.windowId, appIdentifier: parsed.appIdentifier, }); }, },
  • Injected JavaScript IIFE that implements the element search logic: CSS querySelector, XPath via document.evaluate, or text-based XPath. Returns truncated outerHTML on success or 'not found'.
    /** * Find an element using various selector strategies * * @param {Object} params * @param {string} params.selector - Element selector * @param {string} params.strategy - Selector strategy: 'css', 'xpath', or 'text' */ (function(params) { const { selector, strategy } = params; let element; if (strategy === 'text') { // Find element containing text const xpath = "//*[contains(text(), '" + selector + "')]"; const result = document.evaluate( xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); element = result.singleNodeValue; } else if (strategy === 'xpath') { // XPath selector const result = document.evaluate( selector, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); element = result.singleNodeValue; } else { // CSS selector (default) element = document.querySelector(selector); } if (element) { const outerHTML = element.outerHTML; // Truncate very long HTML to avoid overwhelming output const truncated = outerHTML.length > 5000 ? outerHTML.substring(0, 5000) + '...' : outerHTML; return 'Found element: ' + truncated; } return 'Element not found'; })

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hypothesi/mcp-server-tauri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server