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 Predicate

From Leeroopedia
Revision as of 11:58, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Webdriverio_Webdriverio_XPath_Predicate.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Mobile_Testing, iOS_Automation
Last Updated 2026-02-12 00:00 GMT

Overview

The XPath Predicate module converts XPath expressions to iOS Predicate Strings and extracts Accessibility IDs from simple XPath patterns.

Description

This module provides two functions. convertXPathToPredicateString extracts the element type from an XPath (as a type == condition) and all attribute conditions, groups OR conditions, and joins them with AND to produce a complete -ios predicate string: selector. convertXPathToAccessibilityId is a simpler extraction that looks for a single @name or @label attribute value in the XPath and returns it as an accessibility ID. Both functions return null when the XPath does not match their expected patterns.

Usage

These functions are called as part of the static (non-page-source) XPath conversion pipeline to generate predicate strings and accessibility IDs from XPath structure alone.

Code Reference

Source Location

Signature

export function convertXPathToPredicateString(xpath: string): XPathConversionResult | null

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

Import

import { convertXPathToPredicateString, convertXPathToAccessibilityId } from './utils/xpath-predicate.js'

I/O Contract

Inputs

Name Type Required Description
xpath string Yes XPath expression to convert; for predicate string, should contain an element type and/or conditions; for accessibility ID, should contain a single @name or @label attribute

Outputs

Name Type Description
convertXPathToPredicateString return null Object with selector containing the -ios predicate string: prefixed value, or null if no conditions or element type found
convertXPathToAccessibilityId return null The accessibility ID value (name or label attribute), or null if the XPath does not contain a simple @name or @label match

Usage Examples

Converting to Predicate String

import { convertXPathToPredicateString } from './xpath-predicate.js'

const result1 = convertXPathToPredicateString('//XCUIElementTypeButton[@name="Login"]')
// { selector: "-ios predicate string:type == 'XCUIElementTypeButton' AND name == 'Login'" }

const result2 = convertXPathToPredicateString(
    '//XCUIElementTypeStaticText[contains(@label, "Welcome")]'
)
// { selector: "-ios predicate string:type == 'XCUIElementTypeStaticText' AND label CONTAINS 'Welcome'" }

const result3 = convertXPathToPredicateString('//*[@name="Login"]')
// { selector: "-ios predicate string:name == 'Login'" }

Extracting Accessibility ID

import { convertXPathToAccessibilityId } from './xpath-predicate.js'

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

convertXPathToAccessibilityId('//XCUIElementTypeStaticText[@label="Welcome"]')
// 'Welcome'

convertXPathToAccessibilityId('//XCUIElementTypeButton[contains(@name, "Log")]')
// null (contains() is not a simple match)

Related Pages

Page Connections

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