Hoppa till huvudinnehåll

Verktyg

Följande verktyg är tillgängliga via WebdriverIO MCP-servern. Dessa verktyg gör det möjligt för AI-assistenter att automatisera webbläsare och mobilapplikationer.

Session Management

start_browser

Startar en Chrome-webbläsarsession.

Parameters

ParameterTypeMandatoryDefaultDescription
headlessbooleanNofalseRun Chrome in headless mode
windowWidthnumberNo1920Browser window width (400-3840)
windowHeightnumberNo1080Browser window height (400-2160)
navigationUrlstringNo-URL to navigate to after starting the browser

Example

Start a browser with 1920x1080 resolution and navigate to webdriver.io

Support

  • Desktop Browsers

start_app_session

Startar en mobilappsession på iOS eller Android via Appium.

Parameters

ParameterTypeMandatoryDefaultDescription
platformstringYes-Platform to automate: iOS or Android
deviceNamestringYes-Name of the device or simulator/emulator
appPathstringNo*-Path to the app file (.app, .ipa, or .apk)
platformVersionstringNo-OS version (e.g., 17.0, 14)
automationNamestringNoAutoXCUITest (iOS), UiAutomator2 or Espresso (Android)
udidstringNo-Unique device identifier (required for real iOS devices)
noResetbooleanNofalsePreserve app state between sessions
fullResetbooleanNotrueUninstall and reinstall app before session
autoGrantPermissionsbooleanNotrueAutomatically grant app permissions
autoAcceptAlertsbooleanNotrueAutomatically accept system alerts
autoDismissAlertsbooleanNofalseDismiss (instead of accept) alerts
appWaitActivitystringNo-Activity to wait for on launch (Android only)
newCommandTimeoutnumberNo60Seconds before session times out due to inactivity
appiumHoststringNo127.0.0.1Appium server hostname
appiumPortnumberNo4723Appium server port
appiumPathstringNo/Appium server path

*Either appPath must be provided, or noReset: true to connect to an already-running app.

Example

Start an iOS app session on iPhone 15 simulator with my app at /path/to/app.app

Support

  • iOS Simulators
  • iOS Real Devices
  • Android Emulators
  • Android Real Devices

close_session

Stänger den aktuella webbläsar- eller appsessionen.

Parameters

ParameterTypeMandatoryDefaultDescription
detachbooleanNofalseDetach from session instead of closing (keeps browser/app running)

Notes

Sessions with noReset: true or without appPath automatically detach on close to preserve state.

Support

  • Desktop Browsers
  • Mobile Apps

Navigerar till en URL.

Parameters

ParameterTypeMandatoryDescription
urlstringYesThe URL to navigate to

Example

Navigate to https://webdriver.io

Support

  • Desktop Browsers

Element Interaction

click_element

Klickar på ett element identifierat av en selektor.

Parameters

ParameterTypeMandatoryDefaultDescription
selectorstringYes-CSS selector, XPath, or mobile selector
scrollToViewbooleanNotrueScroll element into view before clicking
timeoutnumberNo3000Max time to wait for element (ms)

Notes

  • Supports WebdriverIO text selectors: button=Exact text or a*=Contains text
  • Uses center alignment for scroll positioning

Example

Click the element with selector "#submit-button"

Support

  • Desktop Browsers
  • Mobile Native Apps

set_value

Skriver text i ett inmatningsfält.

Parameters

ParameterTypeMandatoryDefaultDescription
selectorstringYes-Selector for the input element
valuestringYes-Text to type
scrollToViewbooleanNotrueScroll element into view before typing
timeoutnumberNo3000Max time to wait for element (ms)

Notes

Clears existing value before typing new text.

Example

Set the value "john@example.com" in the element with selector "#email"

Support

  • Desktop Browsers
  • Mobile Native Apps

Page Analysis

get_visible_elements

Hämtar synliga och interaktiva element på aktuell sida eller skärm. Detta är det primära verktyget för att upptäcka vilka element som är tillgängliga för interaktion.

Parameters

ParameterTypeMandatoryDefaultDescription
elementTypestringNointeractableType of elements: interactable (buttons/links/inputs), visual (images/SVGs), or all
inViewportOnlybooleanNotrueOnly return elements visible in the viewport
includeContainersbooleanNofalseInclude layout containers (ViewGroup, ScrollView, etc.)
includeBoundsbooleanNofalseInclude element coordinates (x, y, width, height)
limitnumberNo0Maximum elements to return (0 = unlimited)
offsetnumberNo0Number of elements to skip (for pagination)

Returns

{
"total": 42,
"showing": 20,
"hasMore": true,
"elements": [...]
}

Web elements include: tagName, type, id, className, textContent, value, placeholder, href, ariaLabel, role, cssSelector, isInViewport

Mobile elements include: Multiple locator strategies (accessibility ID, resource ID, XPath, UiAutomator/predicates), element type, text, and optionally bounds

Notes

  • Web: Uses an optimized browser script for fast element detection
  • Mobile: Uses efficient XML page source parsing (2 HTTP calls vs 600+ for element queries)
  • Use pagination (limit and offset) for large pages to reduce token usage

Example

Get all visible elements on the page with their coordinates

Support

  • Desktop Browsers
  • Mobile Apps

get_accessibility

Hämtar tillgänglighetsträdet för aktuell sida med semantisk information om roller, namn och tillstånd.

Parameters

ParameterTypeMandatoryDefaultDescription
limitnumberNo100Maximum nodes to return (0 = unlimited)
offsetnumberNo0Number of nodes to skip (for pagination)
rolesstring[]NoAllFilter to specific roles (e.g., ["button", "link", "textbox"])
namedOnlybooleanNotrueOnly return nodes with a name/label

Returns

{
"total": 85,
"showing": 100,
"hasMore": false,
"nodes": [
{ "role": "button", "name": "Submit" },
{ "role": "link", "name": "Home" }
]
}

Notes

  • Browser-only. For mobile apps, use get_visible_elements instead
  • Useful when get_visible_elements doesn't return expected elements
  • namedOnly: true filters out anonymous containers and reduces noise

Support

  • Desktop Browsers

Screenshots

take_screenshot

Tar en skärmdump av aktuell vy.

Parameters

ParameterTypeMandatoryDescription
outputPathstringNoPath to save screenshot file. If omitted, returns base64 data

Returns

Base64-encoded image data (PNG or JPEG) with size information.

Notes

Screenshots are automatically optimized:

  • Maximum dimension: 2000px (scaled down if larger)
  • Maximum file size: 1MB
  • Format: PNG with max compression, or JPEG if needed to meet size limit

Support

  • Desktop Browsers
  • Mobile Apps

Scrolling

scroll

Rullar sidan upp eller ner med ett angivet antal pixlar.

Parameters

ParameterTypeMandatoryDefaultDescription
directionstringYes-Scroll direction: up or down
pixelsnumberNo500Number of pixels to scroll

Notes

Browser-only. For mobile scrolling, use the swipe tool instead.

Support

  • Desktop Browsers

get_cookies

Hämtar cookies från aktuell session.

Parameters

ParameterTypeMandatoryDescription
namestringNoSpecific cookie name to retrieve (omit for all cookies)

Returns

Cookie objects with name, value, domain, path, expiry, secure, and httpOnly properties.

Support

  • Desktop Browsers

Sätter en cookie i aktuell session.

Parameters

ParameterTypeMandatoryDefaultDescription
namestringYes-Cookie name
valuestringYes-Cookie value
domainstringNoCurrentCookie domain
pathstringNo/Cookie path
expirynumberNo-Expiration as Unix timestamp (seconds)
securebooleanNo-Secure flag
httpOnlybooleanNo-HttpOnly flag
sameSitestringNo-SameSite attribute: strict, lax, or none

Support

  • Desktop Browsers

delete_cookies

Raderar cookies från aktuell session.

Parameters

ParameterTypeMandatoryDescription
namestringNoSpecific cookie name to delete (omit to delete all)

Support

  • Desktop Browsers

Touch Gestures (Mobile)

tap_element

Trycker på ett element eller skärmkoordinater.

Parameters

ParameterTypeMandatoryDescription
selectorstringNo*Selector for the element to tap
xnumberNo*X coordinate for tap
ynumberNo*Y coordinate for tap

*Either selector or both x and y are required.

Support

  • Mobile Apps

swipe

Utför en svepgest i angiven riktning.

Parameters

ParameterTypeMandatoryDefaultDescription
directionstringYes-Swipe direction: up, down, left, right
durationnumberNo500Swipe duration in milliseconds (100-5000)
percentnumberNo0.5/0.95Percentage of screen to swipe (0-1)

Notes

  • Default percent: 0.5 for vertical swipes, 0.95 for horizontal swipes
  • Direction indicates content movement: "swipe up" scrolls content up

Example

Swipe up to scroll down the screen

Support

  • Mobile Apps

drag_and_drop

Drar ett element till ett annat element eller koordinater.

Parameters

ParameterTypeMandatoryDescription
sourceSelectorstringYesSource element selector to drag
targetSelectorstringNo*Target element selector to drop onto
xnumberNo*Target X offset (if no targetSelector)
ynumberNo*Target Y offset (if no targetSelector)
durationnumberNoDefault

*Either targetSelector or both x and y are required.

Support

  • Mobile Apps

App Lifecycle (Mobile)

get_app_state

Hämtar appens aktuella tillstånd.

Parameters

ParameterTypeMandatoryDescription
bundleIdstringYesApp identifier (bundle ID for iOS, package name for Android)

Returns

App state: not installed, not running, running in background (suspended), running in background, or running in foreground.

Support

  • Mobile Apps

Context Switching (Hybrid Apps)

get_contexts

Listar alla tillgängliga kontexter (native och webview).

Parameters

None

Returns

Array of context names (e.g., ["NATIVE_APP", "WEBVIEW_com.example.app"]).

Support

  • Mobile Hybrid Apps

get_current_context

Hämtar aktuell aktiv kontext.

Parameters

None

Returns

Current context name (e.g., NATIVE_APP or WEBVIEW_*).

Support

  • Mobile Hybrid Apps

switch_context

Växlar mellan native- och webview-kontexter.

Parameters

ParameterTypeMandatoryDescription
contextstringYesContext name or index (1-based) from get_contexts

Example

Switch to the WEBVIEW_com.example.app context

Support

  • Mobile Hybrid Apps

Device Control (Mobile)

rotate_device

Roterar enheten till en specifik orientering.

Parameters

ParameterTypeMandatoryDescription
orientationstringYesPORTRAIT or LANDSCAPE

Support

  • Mobile Apps

hide_keyboard

Döljer skärmtangentbordet.

Parameters

None

Support

  • Mobile Apps

get_geolocation

Hämtar aktuella GPS-koordinater.

Parameters

None

Returns

Object with latitude, longitude, and altitude.

Support

  • Mobile Apps

set_geolocation

Ställer in enhetens GPS-koordinater.

Parameters

ParameterTypeMandatoryDescription
latitudenumberYesLatitude coordinate (-90 to 90)
longitudenumberYesLongitude coordinate (-180 to 180)
altitudenumberNoAltitude in meters

Example

Set geolocation to San Francisco (37.7749, -122.4194)

Support

  • Mobile Apps

Script Execution

execute_script

Kör JavaScript i webbläsaren eller mobilkommandon via Appium.

Parameters

ParameterTypeMandatoryDescription
scriptstringYesJavaScript code (browser) or mobile command (e.g., mobile: pressKey)
argsarrayNoArguments for the script

Browser Examples

// Get page title
execute_script({ script: "return document.title" })

// Get scroll position
execute_script({ script: "return window.scrollY" })

// Click element by selector
execute_script({ script: "arguments[0].click()", args: ["#myButton"] })

Mobile (Appium) Examples

// Press back key (Android)
execute_script({ script: "mobile: pressKey", args: [{ keycode: 4 }] })

// Activate app
execute_script({ script: "mobile: activateApp", args: [{ appId: "com.example" }] })

// Terminate app
execute_script({ script: "mobile: terminateApp", args: [{ appId: "com.example" }] })

// Deep link
execute_script({ script: "mobile: deepLink", args: [{ url: "myapp://screen", package: "com.example" }] })

// Shell command (Android)
execute_script({ script: "mobile: shell", args: [{ command: "dumpsys", args: ["battery"] }] })

Common Android Key Codes

KeyCode
BACK4
HOME3
ENTER66
MENU82
SEARCH84

More Mobile Commands

For a complete list of available Appium mobile commands, see:

Support

  • Desktop Browsers
  • Mobile Apps (via Appium mobile commands)

Welcome! How can I help?

WebdriverIO AI Copilot