WebdriverIO Appium Helpers
1 min readJul 7, 2022
Those who are moving to WebdriverIO from Java, Python, or Ruby clients in Appium will encounter some differences.
I have written this blog for beginners who have moved from Python to Javascript (WebdriverIO) by collating Python codes to the equivalent WebdriverIO code for the same command. These elementary commands will be helpful if you are new to WebdriverIO.
Find Element By ID
Python
from appium import webdriver
from selenium.webdriver.common.by import By
element = driver.find_element(By.ID, "com.google.android.gms:id/cancel")element.click()
WebdriverIO
element = await $("id=com.google.android.gms:id/cancel");await element.click();
Find Element By Name
Python
from appium import webdriverfrom selenium.webdriver.common.by import Byelement = driver.find_element(By.NAME, “General”)element.click()
WebdriverIO
element = await $('[name="General"]');element.click();
Find Elements
Python
from appium import webdriverfrom selenium.webdriver.common.by import Byelement = driver.find_elements(By.NAME, 'Settings')[1]element.click()
WebdriverIO
element = await $$('[name="Settings"]')[1];element.click();
Find Element By Classname
Python
element = driver.find_element(By.CLASS_NAME, "android.widget.EditText")
WebdriverIO
enter_number = await $(".android.widget.EditText");
Send Keys
Python
enter_number.send_keys("9999999999")
WebdriverIO
await enter_number.addValue("9999999999");
Find Element By Tag Name
Python
element = driver.find_element(By.TAG_NAME, "h1")
WebdriverIO
element = await $("<h1>");
Find Element by Android UI Automator and Scrolling
This is a tricky one.
Android UI automator can be used in Android phones to scroll to an element that doesn’t appear on the screen initially. This can only be found after scrolling through to the bottom.
Python
from appium.webdriver.common.appiumby import AppiumBy###scrollable_id = 'new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Albania (+355)"))'self.driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, scrollable_id)
WebdriverIO
const bottomElementSelector = 'new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Albania (+355)"))';const bottomEl = await $('android=${bottomElementSelector}');