# WebdriverIO v10 documentation: AI Agents > 10 pages. Index of all sections: https://webdriver.io/llms.txt --- Source: https://webdriver.io/docs/ai-agents.md # WebdriverIO for Coding Agents Most WebdriverIO tests today are written together with a coding agent. This page shows how to give an agent the three things it needs to do that well: **current documentation** (so it writes v10 code instead of guessing), **a way to drive the app under test** (so it can explore the UI and verify selectors), and **debuggable test runs** (so it can fix failing tests on its own). ## 1. Give your agent the documentation[​](#1-give-your-agent-the-documentation "Direct link to 1. Give your agent the documentation") Every page on this site is available as clean Markdown, without navigation, scripts or styling: | Resource | URL | Use it for | | ------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | Documentation index | [`https://webdriver.io/llms.txt`](https://webdriver.io/llms.txt) | A curated map of all pages with one-line summaries. Start here. | | Full documentation | [`https://webdriver.io/llms-full.txt`](https://webdriver.io/llms-full.txt) | The complete docs in a single file, for agents with large context windows. | | Any single page | Append `.md` to the URL, e.g. [`/docs/api/browser/url.md`](https://webdriver.io/docs/api/browser/url.md) | Loading exactly the page the agent needs. | | Content negotiation | Request any `/docs/*` URL with `Accept: text/markdown` | Agents and tools that fetch URLs as-is. | Each doc page also has a **Copy page** menu with options to copy the page as Markdown or open it directly in ChatGPT, Claude or Cursor. ### Docs MCP server[​](#docs-mcp-server "Direct link to Docs MCP server") The documentation is also available as a remote MCP server at `https://webdriver.io/mcp`. It gives an agent three tools: `search_docs` to find the right page, `get_page` to read it as Markdown, and `list_sections` to load a whole section at once. Add it next to the WebdriverIO MCP server described below: .mcp.json ``` { "mcpServers": { "webdriverio-docs": { "url": "https://webdriver.io/mcp" } } } ``` For Claude Code, run `claude mcp add --transport http webdriverio-docs https://webdriver.io/mcp`. ## Let your agent use `wdio session`[​](#let-your-agent-use-wdio-session "Direct link to let-your-agent-use-wdio-session") [`wdio session`](/docs/session.md) keeps a WebdriverIO session alive between shell commands. An agent can open a browser, phone or desktop app, snapshot what is on screen, act on refs, and export the steps that worked as a test. That is the default way to drive an app from a coding agent. The [MCP server](/docs/mcp.md) in the next section is the alternative when the agent should call tools instead of the shell. Install the skill into the project: ``` npx wdio session skill --install . ``` That writes `.agents/skills/wdio-session/SKILL.md`. `npm init wdio` writes the same file when you accept coding agent support, and adds the project rules below. An agent can create the project itself. The wizard takes a flag for every question, and `--yes` fills in the defaults for the rest, so it never waits for input: ``` npm init wdio@latest . -- --yes --typescript --framework mocha --browsers chrome --reporters spec ``` `npm init wdio@latest -- --help` lists every flag and its values. See [Answer the wizard with flags](/docs/gettingstarted.md#answer-the-wizard-with-flags). The [WebdriverIO Session](/docs/session.md) section covers targets, snapshots, `exec`, export and debugging. Command reference: [wdio session commands](/docs/session-commands.md). ### Add the docs to your agent[​](#add-the-docs-to-your-agent "Direct link to Add the docs to your agent") To make the docs available in every chat, add the index to your agent: * **Cursor**: add `https://webdriver.io/llms.txt` as a custom doc in the Cursor settings (*Indexing & Docs*), then reference it in chat with `@` and the name you gave it. * **Claude Code / Codex / other CLI agents**: add the link to your project's `AGENTS.md` or `CLAUDE.md` (see [project rules](#3-add-project-rules) below). The agents fetch the pages they need on demand. ## 2. Let your agent drive the browser or app[​](#2-let-your-agent-drive-the-browser-or-app "Direct link to 2. Let your agent drive the browser or app") The [WebdriverIO MCP server](/docs/mcp.md) (`@wdio/mcp`) lets an agent open browsers (Chrome, Firefox, Edge, Safari), native and hybrid mobile apps (via Appium) and cloud devices, inspect the accessibility tree, click, type and take screenshots. Agents use it to explore a page before writing a test, to find robust selectors, and to reproduce a failure step by step. Add it to your MCP client configuration (for example `.mcp.json` or `.cursor/mcp.json` in your project): .mcp.json ``` { "mcpServers": { "wdio-mcp": { "command": "npx", "args": ["-y", "@wdio/mcp"] } } } ``` For Claude Code, register it from the command line: ``` claude mcp add --transport stdio wdio-mcp -- npx -y @wdio/mcp ``` See the [MCP configuration](/docs/mcp/configuration.md) for session options, and [Cloud Providers](/docs/mcp/cloud-providers.md) to run on BrowserStack, Sauce Labs, TestMu AI or TestingBot. ## 3. Add project rules[​](#3-add-project-rules "Direct link to 3. Add project rules") Agents follow the conventions of a project much more reliably when they are written down. Add a section like the following to the `AGENTS.md` (or `CLAUDE.md`, `.cursor/rules`) of your test project and adjust the paths and commands: AGENTS.md ``` ## End-to-end tests (WebdriverIO v10) - Docs: https://webdriver.io/llms.txt - fetch the relevant page as Markdown (append `.md`) before using an API you are not sure about. Do not use APIs from WebdriverIO v8 or older. - Config: `wdio.conf.ts`. Specs: `test/specs/**/*.e2e.ts`. Page objects: `test/pageobjects/`. - Run all tests: `npx wdio run wdio.conf.ts` - Run a single spec: `npx wdio run wdio.conf.ts --spec test/specs/login.e2e.ts` - Tests are async: always `await` commands, e.g. `await $('button').click()`. Never use the removed sync mode. - Prefer user-facing selectors: accessibility name or text (`$('aria/Submit')`, `$('button=Submit')`), then `data-testid`. Avoid XPath and generated CSS classes. - Rely on auto-waiting and `expect-webdriverio` matchers (`await expect($('h1')).toHaveText('Welcome')`) instead of `browser.pause()`. - To explore the app or verify a selector, use the `wdio-mcp` MCP server. - To drive the app from the shell, follow `.agents/skills/wdio-session/SKILL.md` (`npx wdio session`). - When a test fails, read the DevTools trace in `test-results/` (see `transcript.md`) before changing code. ``` The rules above reflect the recommendations in [Best Practices](/docs/bestpractices.md), [Selectors](/docs/selectors.md) and [Auto-waiting](/docs/autowait.md). ## 4. Let the agent debug failing tests[​](#4-let-the-agent-debug-failing-tests "Direct link to 4. Let the agent debug failing tests") The [WebdriverIO DevTools](/docs/devtools.md) service can record a **trace** of every run: a portable artifact with a step-by-step Markdown transcript, screenshots, accessibility-tree snapshots and network logs for each action. This gives an agent the same information a human gets from watching the test, without needing a browser window. Install the service and enable trace mode: ``` npm install @wdio/devtools-service --save-dev ``` wdio.conf.ts ``` export const config: WebdriverIO.Config = { // ... services: [ ['devtools', { mode: 'trace', // one trace per test makes it easy to hand a single failure to an agent traceGranularity: 'test', // plain files instead of a zip, so agents can read them directly traceFormat: 'ndjson-directory' }] ] } ``` After a run, traces are written to `test-results/`. Point your agent at the folder of the failing test and ask it to read `transcript.md` first. See [Trace Mode](/docs/devtools/wdio/trace-mode.md) for all options, including granularity and retention. ## Recommended workflow[​](#recommended-workflow "Direct link to Recommended workflow") 1. Ask the agent to explore the feature under test with the MCP server and propose selectors. 2. Let it write the spec and page object following your project rules, fetching WebdriverIO docs pages as needed. 3. Have it run the single spec with `--spec` and iterate until it passes. 4. If a test fails in CI, give the agent the trace of that test and let it fix the test or report the bug. ## Next steps[​](#next-steps "Direct link to Next steps") * [Getting Started](/docs/gettingstarted.md) - create a project with `npm init wdio@latest` * [WebdriverIO MCP](/docs/mcp.md) - all tools the MCP server provides * [DevTools](/docs/devtools.md) - live mode and trace mode * [Best Practices](/docs/bestpractices.md) - what good WebdriverIO tests look like * [From v9 to v10](/docs/v10-migration.md#migrate-with-a-coding-agent) - the migration skill for an existing suite --- Source: https://webdriver.io/docs/ai-steps.md # AI Steps in Tests `@wdio/ai-service` lets a test describe a step instead of scripting it: `browser.act('Add a blue shirt to the cart')` asks your model to perform it, records the WebdriverIO commands it ran, and replays them from a cache file on every later run. The model is only called again when the page changed and a recorded step can no longer be repaired without it. Use it for flows whose markup changes often, or to get a test running before you know the selectors. Use plain WebdriverIO commands for everything you already know how to script. ## Set up the service[​](#set-up-the-service "Direct link to Set up the service") Install the service and the LangChain package of your model provider: ``` npm install --save-dev @wdio/ai-service @langchain/anthropic zod ``` Add the service to your config and set the API key of the provider (`ANTHROPIC_API_KEY` here) in the environment: wdio.conf.ts ``` export const config: WebdriverIO.Config = { specs: ['./test/specs/**/*.e2e.ts'], capabilities: [{ browserName: 'chrome', webSocketUrl: true }], framework: 'mocha', services: [['ai', { model: 'anthropic:claude-sonnet-5-5' }]] } ``` `webSocketUrl: true` opens a WebDriver BiDi session. The service works over WebDriver Classic too, but BiDi lets it check what every step did and read the API responses of the page. See the [AI Service](/docs/ai-service.md) page for every option and provider, including local models through Ollama. ## Write a test[​](#write-a-test "Direct link to Write a test") test/specs/cart.e2e.ts ``` import { browser, expect } from '@wdio/globals' import { z } from 'zod' describe('cart', () => { it('adds a shirt', async () => { await browser.url('https://shop.example/') await browser.act('Add a blue shirt in size M to the shopping cart') const cart = await browser.extract( 'the line items in the cart', z.array(z.object({ name: z.string(), size: z.string(), qty: z.number() })) ) expect(cart).toContainEqual({ name: 'Blue Shirt', size: 'M', qty: 1 }) }) }) ``` * `act` performs the step and never asserts. Check the outcome with `expect`. * `extract` only reads the page and validates the answer against the schema. It is never cached. * Secrets go into placeholders. The model sees `{{password}}`, never the value: ``` await browser.act('Log in as {{email}} with password {{password}}', { values: { email: process.env.SHOP_USER!, password: process.env.SHOP_PASS! } }) ``` * Call `act` on an element to keep the model inside it, or on a held frame or tab: ``` await $('form#billing').act('Fill in a valid German address') ``` ## Record once, replay without a model[​](#record-once-replay-without-a-model "Direct link to Record once, replay without a model") The first run records the steps of every `act` call in `__act__/.json` next to the spec: ``` npx wdio run wdio.conf.ts --spec test/specs/cart.e2e.ts ``` Commit the `__act__` directory. Later runs replay the recorded commands, so a passing run makes no model calls and costs no tokens. | `cache` | Use it for | | ---------------- | ---------------------------------------------------------------------------------------------------------------- | | `auto` (default) | `write` locally, `heal` when `process.env.CI` is set | | `write` | recording and updating the cache files | | `heal` | CI: repair failing steps, write the repaired entries to `/act-cache/` and leave the cache files alone | | `locked` | CI runs that must not call a model: replay only, fail when a step cannot be repaired without the model | | `off` | always ask the model | Run `npx wdio run wdio.conf.ts -s` to record every `act` call again. ## Review heals[​](#review-heals "Direct link to Review heals") When a recorded step fails, the service first tries the other selectors it recorded for the element and then its role and accessible name. Only if that fails does the model continue from the failing step. Every replayed or healed step has to do what it did when it was recorded: send the same requests, navigate to the same page and change the same parts of the page. A heal onto a similar but wrong button is rejected. The run ends with a summary: ``` @wdio/ai-service: 42 act calls · 39 from cache · 2 healed without the model · 1 healed by the model · 0 recorded by the model · 3.1k tokens Healed: cart.e2e.ts › cart adds a shirt "Add a blue shirt in size M to the shopping cart": step 2 [data-testid="add"] → role/button[name="Add to cart"] (without the model) evidence: ./logs/ai/heals/cart.e2e.ts-cart-adds-a-shirt-1c71c48d ``` The evidence folder holds a screenshot of the page when the step failed, one after each healing step, and a video of the heal in browsers that record a WebDriver BiDi screencast (Firefox today). Review the heal, then commit the updated cache file. ## Turn steps into plain code[​](#turn-steps-into-plain-code "Direct link to Turn steps into plain code") Once a flow is stable, replace its `act` calls with the recorded commands: ``` npx wdio-ai eject test/specs/cart.e2e.ts ``` ``` // act: Add a blue shirt in size M to the shopping cart await $('role/link[name="Blue Shirt"]').click() await $('role/combobox[name="Size"]').selectByVisibleText('M') await $('role/button[name="Add to cart"]').click() ``` ## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting") | Error | Fix | | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `act("…") failed: no model is configured. Set the `model` option of the service or the WDIO_AI_MODEL environment variable.` | Set `model` in the service options or export `WDIO_AI_MODEL=anthropic:claude-sonnet-5-5`. | | `[@wdio/ai-service] The "anthropic" provider needs "@langchain/anthropic". Install it with `npm install --save-dev @langchain/anthropic`.` | Install the provider package. | | `[@wdio/ai-service] No API key for "anthropic". Set ANTHROPIC_API_KEY or pass `apiKey` in the model config.` | Export the key in the shell or CI secret that runs the tests. | | `act("…") failed: no cached steps for "…" and the cache is locked` | Record the call locally with `cache: 'write'` and commit the `__act__` file. | | `act("…") failed: cached step 1 (…) ran, but the step no longer causes POST /api/cart → 2xx. The app may have changed behavior, not just markup.` | The element is still there but does something else: a regression, not a markup change. Check the app. | | `act("…") failed: …` followed by `Evidence: ` | The model could not complete the instruction. The folder has every snapshot it took, the console and network events and the steps that ran. | ## Next steps[​](#next-steps "Direct link to Next steps") * [AI Service](/docs/ai-service.md): every option, the cache format, step effects and the workspace * [Selectors](/docs/selectors.md#role-selector): the `role/` selector recorded steps use * [WebdriverIO for Coding Agents](/docs/ai-agents.md): write tests together with a coding agent --- Source: https://webdriver.io/docs/mcp.md # MCP (Model Context Protocol) ## What can it do?[​](#what-can-it-do "Direct link to What can it do?") WebdriverIO MCP is a **Model Context Protocol (MCP) server** that enables AI assistants to automate and interact with web browsers and mobile applications. ### Why WebdriverIO MCP?[​](#why-webdriverio-mcp "Direct link to Why WebdriverIO MCP?") * **Mobile-First**: Unlike browser-only MCP servers, WebdriverIO MCP supports iOS and Android native app automation via Appium * **Cross-Platform Selectors**: Smart element detection generates multiple locator strategies (accessibility ID, XPath, UiAutomator, iOS predicates) automatically * **WebdriverIO Ecosystem**: Built on the battle-tested WebdriverIO framework with its rich ecosystem of services and reporters It provides a unified interface for: * 🖥️ **Desktop Browsers** (Chrome, Firefox, Edge, Safari, headed or headless) * **Electron Apps** (renderer automation, main-process scripts and deeplinks) * 📱 **Native Mobile Apps** (iOS Simulators / Android Emulators / Real Devices via Appium) * 📳 **Hybrid Mobile Apps** (Native + WebView context switching via Appium) * ☁️ **Cloud Devices** (BrowserStack, Sauce Labs, TestMu, TestingBot and Digital.ai real device and browser clouds) through the [`@wdio/mcp`](https://www.npmjs.com/package/@wdio/mcp) package. This allows AI assistants to: * **Launch and control browsers** with configurable dimensions, headless mode, and optional initial navigation * **Navigate websites** and interact with elements (click, type, scroll) * **Analyze page content** via accessibility tree and visible elements detection with pagination support * **Take screenshots** automatically optimized (resized, compressed to max 1MB) * **Manage cookies** for session handling * **Control mobile devices** including gestures (tap, swipe, drag and drop) * **Switch contexts** in hybrid apps between native and webview * **Execute scripts** - JavaScript in browsers, Appium mobile commands on devices * **Handle device features** like rotation, keyboard, geolocation * and much more, see the [Tools](/docs/mcp/tools.md) and [Configuration](/docs/mcp/configuration.md) options info NOTE For Mobile Apps Mobile automation requires a running Appium server with the appropriate drivers installed. See [Prerequisites](#prerequisites) for setup instructions. ## Installation[​](#installation "Direct link to Installation") The easiest way to use `@wdio/mcp` is via npx without any local installation: ``` npx @wdio/mcp ``` Or install it globally: ``` npm install -g @wdio/mcp ``` ## Usage with Claude[​](#usage-with-claude "Direct link to Usage with Claude") To use WebdriverIO MCP with Claude, modify the configuration file: ``` { "mcpServers": { "wdio-mcp": { "command": "npx", "args": ["-y", "@wdio/mcp"] } } } ``` After adding the configuration, restart your harness. The WebdriverIO MCP tools will be available for browser and mobile automation tasks. ### Usage with Claude Code[​](#usage-with-claude-code "Direct link to Usage with Claude Code") Claude Code automatically detects MCP servers. You can configure it in your project's `.claude/settings.json`, or `.mcp.json`. Or add it to .claude.json globally with executing: ``` claude mcp add --transport stdio wdio-mcp -- npx -y @wdio/mcp ``` Validate it by running the `/mcp` command inside claude code. ## Quick Start Examples[​](#quick-start-examples "Direct link to Quick Start Examples") ### Browser Automation[​](#browser-automation "Direct link to Browser Automation") Ask Claude to automate browser tasks: ``` "Open Chrome and navigate to https://webdriver.io" "Click the 'Get Started' button" "Take a screenshot of the page" "Find all visible links on the page" ``` ### Mobile App Automation[​](#mobile-app-automation "Direct link to Mobile App Automation") Ask Claude to automate mobile apps: ``` "Start my iOS app on the iPhone 15 simulator" "Tap the login button" "Swipe up to scroll down" "Take a screenshot of the current screen" ``` ## Capabilities[​](#capabilities "Direct link to Capabilities") ### Browser Automation[​](#browser-automation-1 "Direct link to Browser Automation") | Feature | Description | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | **Session Management** | Launch Chrome, Firefox, Edge, or Safari in headed/headless mode with custom dimensions; attach to an existing Chrome instance via CDP | | **Navigation** | Navigate to URLs; manage multiple tabs | | **Element Interaction** | Click elements, type text, find elements by various selectors | | **Page Analysis** | Get interactable elements (with pagination), accessibility tree (with role filtering) | | **Screenshots** | Capture screenshots (auto-optimized to max 1MB) | | **Scrolling** | Scroll up/down by configurable pixel amounts | | **Cookie Management** | Get, set, and delete cookies | | **Device Emulation** | Emulate mobile/tablet viewports in browser (BiDi required) | | **Script Execution** | Execute custom JavaScript in browser context | ### Electron Automation[​](#electron-automation "Direct link to Electron Automation") | Feature | Description | | ------------------------ | ---------------------------------------------------------------------------------------------------- | | **Session Management** | Start an Electron app with `platform: "electron"`; deeplink scheme and project root are set at start | | **Renderer Automation** | Automate the renderer UI of the app | | **Main-Process Scripts** | Run JavaScript with access to the Electron APIs in the main process | | **Deeplinks** | Trigger deeplinks through the running app | | **Mocking** | Mock Electron API functions (requires `enable_tools` for the `mocks` group) | ### Mobile App Automation (iOS/Android)[​](#mobile-app-automation-iosandroid "Direct link to Mobile App Automation (iOS/Android)") | Feature | Description | | ---------------------- | ----------------------------------------------------------------------- | | **Session Management** | Launch apps on simulators, emulators, or real devices | | **Touch Gestures** | Tap (element or coordinates), swipe, drag and drop | | **Element Detection** | Smart element detection with multiple locator strategies and pagination | | **App Lifecycle** | Get app state (foreground, background, not running, not installed) | | **Context Switching** | Switch between native and webview contexts in hybrid apps | | **Device Control** | Rotate device, keyboard control, GPS override | | **Permissions** | Automatic permission and alert handling | | **Script Execution** | Execute Appium mobile commands (pressKey, deepLink, shell, etc.) | ### Cloud Providers[​](#cloud-providers "Direct link to Cloud Providers") | Feature | Description | | -------------------- | ----------------------------------------------------------------------------------------------------------- | | **Browser Sessions** | Run browser sessions on BrowserStack, Sauce Labs, TestMu, TestingBot, or Digital.ai (Windows, macOS, Linux) | | **Mobile Sessions** | Run app sessions on real devices via BrowserStack, Sauce Labs, TestMu, TestingBot, or Digital.ai | | **App Management** | Upload `.apk`/`.ipa` files; list previously uploaded apps across all five providers | | **Local Tunnel** | Auto-manage provider-specific tunnel binaries for accessing localhost | | **Reporting** | Tag sessions with project/build/session labels (works identically across all providers) | ## Prerequisites[​](#prerequisites "Direct link to Prerequisites") ### Browser Automation[​](#browser-automation-2 "Direct link to Browser Automation") * **Chrome, Firefox, Edge, or Safari** must be installed * WebdriverIO handles automated driver management ### Mobile Automation[​](#mobile-automation "Direct link to Mobile Automation") #### iOS[​](#ios "Direct link to iOS") 1. **Install Xcode** from the Mac App Store 2. **Install Xcode Command Line Tools**: ``` xcode-select --install ``` 3. **Install Appium**: ``` npm install -g appium ``` 4. **Install the XCUITest driver**: ``` appium driver install xcuitest ``` 5. **Start the Appium server**: ``` appium ``` 6. **For Simulators**: Open Xcode → Window → Devices and Simulators to create/manage simulators 7. **For Real Devices**: You'll need the device UDID (40-character unique identifier) #### Android[​](#android "Direct link to Android") 1. **Install Android Studio** and set up Android SDK 2. **Set environment variables**: ``` export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/platform-tools ``` 3. **Install Appium**: ``` npm install -g appium ``` 4. **Install the UiAutomator2 driver**: ``` appium driver install uiautomator2 ``` 5. **Start the Appium server**: ``` appium ``` 6. **Create an emulator** via Android Studio → Virtual Device Manager 7. **Start the emulator** before running tests ## Architecture[​](#architecture "Direct link to Architecture") ### How It Works[​](#how-it-works "Direct link to How It Works") WebdriverIO MCP acts as a bridge between AI assistants and browser/mobile automation: ``` ┌─────────────────┐ MCP Protocol ┌─────────────────┐ │ Claude Desktop │ ◄──────────────────► │ @wdio/mcp │ │ or Claude Code │ (stdio or HTTP) │ Server │ └─────────────────┘ └────────┬────────┘ │ WebDriverIO API │ ┌──────────────────────────────┼──────────────────────────────┐ │ │ │ ┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐ │ Browser │ │ Appium │ │ Cloud │ │ (local/CDP) │ │ (iOS/Android)│ │ Providers │ └───────────────┘ └───────────────┘ └───────────────┘ ``` ### Session Management[​](#session-management "Direct link to Session Management") * **Named multi-session**: give a session a `name` in `start_session` or `attach_session`, and it runs alongside the others when started with `onExisting: "keep"`. Without `keep`, a new session replaces the active one * **Targeting**: every tool except the sessionless ones (`start_session`, `attach_session`, `launch_chrome`, `list_apps`, `upload_app`, `query_docs`, `enable_tools`) takes a `session` argument with a session name or ID. Without it, the tool uses the default session. Results are prefixed `[session: name (id8)]` when a target is passed or more than one session is live * **Session state** is maintained globally across tool calls * **Auto-detach**: Sessions with preserved state (`noReset: true`) automatically detach on close ### Element Detection[​](#element-detection "Direct link to Element Detection") #### Browser (Web)[​](#browser-web "Direct link to Browser (Web)") * Uses an optimized browser script to find all visible, interactable elements * Returns elements with CSS selectors, IDs, classes, and ARIA information * Supports viewport filtering and pagination #### Mobile (Native Apps)[​](#mobile-native-apps "Direct link to Mobile (Native Apps)") * Uses efficient XML page source parsing (2 HTTP calls vs 600+ for traditional queries) * Platform-specific element classification for Android and iOS * Generates multiple locator strategies per element: * Accessibility ID (cross-platform, most stable) * Resource ID / Name attribute * Text / Label matching * XPath (full and simplified) * UiAutomator (Android) / Predicates (iOS) ## Selector Syntax[​](#selector-syntax "Direct link to Selector Syntax") The MCP server supports multiple selector strategies. See [Selectors](/docs/mcp/selectors.md) for detailed documentation. ### Web (CSS/XPath)[​](#web-cssxpath "Direct link to Web (CSS/XPath)") ``` # CSS Selectors button.my-class #element-id [data-testid="login"] # XPath //button[@class='submit'] //a[contains(text(), 'Click')] # Text Selectors (WebdriverIO specific) button=Exact Button Text a*=Partial Link Text ``` ### Mobile (Cross-Platform)[​](#mobile-cross-platform "Direct link to Mobile (Cross-Platform)") ``` # Accessibility ID (recommended - works on iOS & Android) ~loginButton # Android UiAutomator android=new UiSelector().text("Login") # iOS Predicate String -ios predicate string:label == "Login" # iOS Class Chain -ios class chain:**/XCUIElementTypeButton[`label == "Login"`] # XPath (works on both platforms) //android.widget.Button[@text="Login"] //XCUIElementTypeButton[@label="Login"] ``` ## Available Tools[​](#available-tools "Direct link to Available Tools") The MCP server provides 42 tools for browser, Electron and mobile automation. See [Tools](/docs/mcp/tools.md) for the complete reference, including which tools are hidden until a group is enabled with `enable_tools` (see [Tool visibility](/docs/mcp/tools.md#tool-visibility)). ### Recommended Workflow[​](#recommended-workflow "Direct link to Recommended Workflow") 1. Take a `snapshot` to read the page. Its refs, such as `e12`, are what the other tools accept as selectors. 2. Act on those refs with `click_element`, `set_value` or `select_option`. 3. For several steps in a row, such as filling a form and then submitting it, send one `perform_actions` call rather than one call per step. Refs from the latest result stay valid until the page changes. After that, take a new snapshot. | Tool | Platform | Description | | --------------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- | | `start_session` | all | Start a browser, Electron or mobile session (local or cloud provider) | | `attach_session` | all | Attach to an existing WebDriver or Appium session by ID or name (`attach` group) | | `close_session` | all | Close or detach from a session | | `launch_chrome` | browser | Open Chrome with remote debugging for CDP attach (`attach` group) | | `navigate` | browser | Load a URL in the current tab | | `get_tabs` | browser | List all open tabs | | `switch_tab` | browser | Focus a tab by handle or index | | `switch_frame` | browser | Switch into an iframe by selector, or back to top-level | | `scroll` | browser | Scroll the page up or down | | `click_element` | all | Click an element (ref or selector) | | `set_value` | all | Replace the text of an input (ref or selector) | | `select_option` | browser | Select a `` by its text. The result lists what changed on the page. **Browser-only.** | Parameter | Type | Required | Description | | ---------- | ------ | -------- | ----------------------------------------------------------------- | | `selector` | string | ✓ | Ref from `snapshot` (e.g. `e12`), or a selector of the `` fields are masked * You should avoid automating sensitive credentials * Use test accounts for automation ## Contributing[​](#contributing "Direct link to Contributing") ### How can I contribute?[​](#how-can-i-contribute "Direct link to How can I contribute?") Visit the [GitHub repository](https://github.com/webdriverio/mcp) to: * Report bugs * Request features * Submit pull requests ### Where can I get help?[​](#where-can-i-get-help "Direct link to Where can I get help?") * [WebdriverIO Discord](https://discord.webdriver.io/) * [GitHub Issues](https://github.com/webdriverio/mcp/issues) * [WebdriverIO Documentation](https://webdriver.io/)