Skip to main content

Find By AI Method

SmartDriver adds additional methods to allow you to only use element names to find elements. This will return the MobileElement that best matches the visual one.

Below is the same test case as the basic example where we will go into the "new" section of the app.

tip

You can write your entire test, and then execute it with interactive mode to quickly write larger tests.

import time
import unittest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

from devtools_ai.appium import SmartDriver


def _main() -> None:
"""Main driver"""
desired_caps = dict(
platformName='Android',
automationName='uiautomator2',
deviceName='emulator-5554',
app='/path/to/app.apk' # <-- Replace with a valid APK path
)
appium_driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

driver = SmartDriver(appium_driver, "??API_KEY??")

done_button = driver.find_by_ai('done_button')
done_button.click()
time.sleep(1)

new_button = driver.find_by_ai('new_button')
new_button.click()
time.sleep(1)


if __name__ == "__main__":
_main()