Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wswebcreation
Last active August 10, 2022 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wswebcreation/f82b47c0c76a0d8d4c50ce3747120fa0 to your computer and use it in GitHub Desktop.
Save wswebcreation/f82b47c0c76a0d8d4c50ce3747120fa0 to your computer and use it in GitHub Desktop.
Preferred Native Appium Selectors for WebdriverIO
// The `~` tells WebdriverIO that it needs to look for an accessibiltyID
// Android: `content description`
// iOS: `accessibility id`
$('~accessibiltyID').click();
// -ios predicate string
const loginButton = 'type == \'XCUIElementTypeOther\' && name CONTAINS \'test-LOGIN\'';
$(`-ios predicate string:${ loginButton }`).click();
// -ios class chain, to make complex selectors
const classChainSwagItem = '**/XCUIElementTypeOther[`name CONTAINS "test-Item"`]/**/XCUIElementTypeOther[`name CONTAINS "Sauce Labs Bike Light" AND name CONTAINS "ADD TO CART"`]/**/XCUIElementTypeOther[`name == "test-ADD TO CART"`]';
$(`-ios class chain:${ classChainSwagItem }`).click();
// -android uiautomator
const androidButton = 'new UiSelector().text("Cancel").className("android.widget.Button")';
$(`android=${androidButton}`).click();
// className for iOS
$('UIATextField').click();
// className for Android
$('android.widget.DatePicker').click();
// XPATH
const xpathSwagItem = '//XCUIElementTypeStaticText[contains(@value,"Sauce Labs Bike Light")]//ancestor::*[@name="test-Item"]//*[@name="test-ADD TO CART"]';
$(xpathSwagItem).click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment