Skip to main content

AppiumDriver API


Description

IAppiumDriverAPI AppiumDriver

This interface provides methods for finding and interacting with elements in Android apps. It's a key tool for automating user interface interactions via ZennoDroid.

When an element is successfully found, it returns an IAndroidElementAPI object; if not, it returns null.


Methods

Get the element that's currently in focus.

IAndroidElementAPI ActiveElement()

Example

var driver = instance.DroidInstance.AppiumDriver;

var de = driver.ActiveElement(); // Get the element in focus

Find an element by the content-desc property.

IAndroidElementAPI FindElementByAccessibilityId(string id)

Parameters:

string id // The value of the content-desc property.

Example

var driver = instance.DroidInstance.AppiumDriver;

var de = driver.FindElementByAccessibilityId("Chrome search"); // Find element by content-desc property
if (de == null)
throw new Exception("Element not found");

de.Click(); // Click the element

Find an element by the class property.

IAndroidElementAPI FindElementByClassName(string className)

Parameters:

string className // The value of the class property.

Example

var driver = instance.DroidInstance.AppiumDriver;

var de = driver.FindElementByClassName("android.widget.EditText"); // Find element by class name
if (de == null)
throw new Exception("Element not found");

de.SendText("Hello world!"); // Write text in the element's field

Find an element by the resource-id property.

IAndroidElementAPI FindElementById(string id)

Parameters:

string id // The value of the resource-id property.

Example

var driver = instance.DroidInstance.AppiumDriver;

var de = driver.FindElementById("com.android.chrome:id/title"); // Find element by resource-id property
if (de == null)
throw new Exception("Element not found");

var text = de.Text; // Get the text of the element

Find an element by xPath.

IAndroidElementAPI FindElementByXPath(string xpath)

Parameters:

string xpath // xPath to find the element.

Example

var driver = instance.DroidInstance.AppiumDriver;

var de = driver.FindElementByXPath("//*[@text=\"Display\"]"); // Find element by xPath
if (de == null)
throw new Exception("Element not found");

de.Click(); // Click the element

Find an element via UiSelector.

IAndroidElementAPI FindElementByUiAutomator(string uiSelector)

Parameters:

string uiSelector  // The uiSelector to find the element.

Example

var driver = instance.DroidInstance.AppiumDriver;

var de = driver.FindElementByUiAutomator("new UiSelector().textContains(\"screen\")"); // Find element by UiSelector
if (de == null)
throw new Exception("Element not found");

de.Click(); // Click the element

Find an array of elements by the content-desc property.

IAndroidElementAPI[] FindElementsByAccessibilityId(string id)

Parameters:

string id  // The value of the content-desc property.

Example

var driver = instance.DroidInstance.AppiumDriver;

var des = driver.FindElementsByAccessibilityId("Chrome search"); // Find an array of elements by content-desc property
if (des == null)
throw new Exception("Elements not found");

var count = des.Length; // Number of elements found

Find an array of elements by the resource-id property.

IAndroidElementAPI[] FindElementsById(string id)

Parameters:

string id  // The value of the resource-id property.

Example

var driver = instance.DroidInstance.AppiumDriver;

var des = driver.FindElementsById("com.android.chrome:id/title"); // Find an array of elements by resource-id property
if (des == null)
throw new Exception("Elements not found");

var count = des.Length; // Number of elements found

Find an array of elements by the class property.

IAndroidElementAPI[] FindElementsByClassName(string className)

Parameters:

string className  // The value of the class property.

Example

var driver = instance.DroidInstance.AppiumDriver;

var des = driver.FindElementsByClassName("android.widget.EditText"); // Find an array of elements by class name
if (des == null)
throw new Exception("Elements not found");

var count = des.Length; // Number of elements found

Find an array of elements by xPath.

IAndroidElementAPI[] FindElementsByXPath(string xpath)

Parameters:

string xpath  // xPath for finding elements.

Example

var driver = instance.DroidInstance.AppiumDriver;

var des = driver.FindElementsByXPath("//*[@text=\"Display\"]");// Find an array of elements by xPath
if (des == null)
throw new Exception("Elements not found");

var count = des.Length; // Number of elements found

Find an array of elements via UiSelector.

IAndroidElementAPI[] FindElementsByUiAutomator(string uiSelector)

Parameters:

string uiSelector // The uiSelector to find the element.

Example

var driver = instance.DroidInstance.AppiumDriver;

var des = driver.FindElementsByUiAutomator("new UiSelector().textContains(\"screen\")"); // Find an array of elements by UiSelector
if (des == null)
throw new Exception("Elements not found");

var count = des.Length; // Number of elements found

Scroll the screen to an element by its content-desc property.

void ScrollToElementByAccessibilityId(string id, int maxSwipes)

Parameters:

string id // The value of the content-desc property.
int maxSwipes // Number of swipes.

Example

var driver = instance.DroidInstance.AppiumDriver;

var countScroll = 3; // Number of scrolls
driver.ScrollToElementByAccessibilityId("Chrome search", countScroll); // Scroll to element by content-desc property

Scroll the screen to an element by its class property.

void ScrollToElementByClassName(string className, int maxSwipes)

Parameters:

string className // The value of the class property.
int maxSwipes // Number of swipes.

Example

var driver = instance.DroidInstance.AppiumDriver;

var countScroll = 3; // Number of scrolls
driver.ScrollToElementByClassName("android.widget.ImageView", countScroll); // Scroll to element by class name

Scroll the screen to an element via UiSelector.

void ScrollToElementByUiAutomator(string uiSelector, int maxSwipes)

Parameters:

string uiSelector  // The uiSelector to find the element.
int maxSwipes // Number of swipes.

Example

var driver = instance.DroidInstance.AppiumDriver;

var countScroll = 3; // Number of scrolls
driver.ScrollToElementByUiAutomator("new UiSelector().text(\"Display\")", countScroll); // Scroll to element by UiSelector