Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Webdriverio Webdriverio XPath Detection

From Leeroopedia
Knowledge Sources
Domains Mobile_Testing, XPath_Processing
Last Updated 2026-02-12 00:00 GMT

Overview

The XPath Detection module analyzes XPath expressions to identify unmappable features, assess complexity, extract element types, and detect wildcard usage.

Description

This module provides four exported functions. detectUnmappableXPathFeatures scans an XPath for axes (following-sibling, preceding-sibling, ancestor, etc.), functions (normalize-space, translate, position, count, etc.), complex substring patterns, and union operators that cannot be converted to native iOS selectors. isComplexXPath checks for complex patterns (OR, AND, contains, etc.) that indicate the XPath should not be simplified to an Accessibility ID. extractElementTypeFromXPath extracts the XCUIElementType* element type from an XPath. isWildcardXPath checks if the XPath starts with //*. The module relies on constant arrays from xpath-constants.js for pattern matching.

Usage

These functions are used by the converter pipeline to pre-filter XPath expressions before attempting conversion, avoiding unnecessary processing of unsupported patterns.

Code Reference

Source Location

Signature

export function detectUnmappableXPathFeatures(xpath: string): string[]

export function isComplexXPath(xpath: string): boolean

export function extractElementTypeFromXPath(xpath: string): string | null

export function isWildcardXPath(xpath: string): boolean

Import

import {
    detectUnmappableXPathFeatures,
    isComplexXPath,
    extractElementTypeFromXPath,
    isWildcardXPath
} from './utils/xpath-detection.js'

I/O Contract

Inputs

Name Type Required Description
xpath string Yes XPath expression to analyze

Outputs

Name Type Description
detectUnmappableXPathFeatures return string[] )')
isComplexXPath return boolean True if the XPath contains OR, AND, contains(), or other complex patterns
extractElementTypeFromXPath return null The iOS element type (e.g., 'XCUIElementTypeButton') or null if not found
isWildcardXPath return boolean True if the XPath starts with //*

Usage Examples

Detecting Unmappable Features

import { detectUnmappableXPathFeatures } from './xpath-detection.js'

const features1 = detectUnmappableXPathFeatures(
    '//XCUIElementTypeButton/following-sibling::XCUIElementTypeStaticText'
)
// ['following-sibling axis']

const features2 = detectUnmappableXPathFeatures(
    '//XCUIElementTypeButton[@name="OK"] | //XCUIElementTypeButton[@name="Cancel"]'
)
// ['union operator (|)']

const features3 = detectUnmappableXPathFeatures(
    '//XCUIElementTypeButton[@name="Login"]'
)
// [] (no unmappable features)

Checking Complexity

import { isComplexXPath, extractElementTypeFromXPath, isWildcardXPath } from './xpath-detection.js'

isComplexXPath('//XCUIElementTypeButton[@name="OK" or @name="Cancel"]')
// true

extractElementTypeFromXPath('//XCUIElementTypeButton[@name="Login"]')
// 'XCUIElementTypeButton'

isWildcardXPath('//*[@name="Login"]')
// true

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment