Skip to main content

AppiumDriver API

Description

IAppiumDriverAPI provides access to Appium driver capabilities in ZennoDroid. Used for finding UI elements and interacting with them via standard Android automation mechanisms (UIAutomator, XPath, etc.).

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

Methods

ActiveElement

  • IAndroidElementAPI ActiveElement()
    Returns the currently active (focused) element.

    Returns:
    An IAndroidElementAPI object.

Example

var driver = instance.DroidInstance.AppiumDriver;

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

FindElementByAccessibilityId

  • IAndroidElementAPI FindElementByAccessibilityId(string id)
    Finds an element by Accessibility ID (content-desc).

    Parameters:

    • id — value of content-desc.

    Returns:
    The found element or null.

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

FindElementByClassName

  • IAndroidElementAPI FindElementByClassName(string className)
    Finds an element by class name.

    Parameters:

    • className — class name (e.g. android.widget.TextView).

    Returns:
    The found element or null.

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

FindElementById

  • IAndroidElementAPI FindElementById(string id)
    Finds an element by resource-id.

    Parameters:

    • id — resource identifier.

    Returns:
    The found element or null.

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

FindElementByUiAutomator

  • IAndroidElementAPI FindElementByUiAutomator(string uiSelector)
    Finds an element via UiSelector.

    Parameters:

    • uiSelector — selector string (e.g. new UiSelector().text("Login")).

    Returns:
    The found element or null.

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

FindElementByXPath

  • IAndroidElementAPI FindElementByXPath(string xpath)
    Finds an element by XPath.

    Parameters:

    • xpath — XPath expression.

    Returns:
    The found element or null.

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

FindElementsByAccessibilityId

  • IAndroidElementAPI[] FindElementsByAccessibilityId(string id)
    Finds all elements by Accessibility ID (content-desc).

    Parameters:

    • id — value of content-desc.

    Returns:
    Array of elements.

Example

var driver = instance.DroidInstance.AppiumDriver;

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

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

FindElementsById

  • IAndroidElementAPI[] FindElementsById(string id)
    Finds all elements by resource-id.

    Parameters:

    • id — resource identifier.

    Returns:
    Array of elements.

Example

var driver = instance.DroidInstance.AppiumDriver;

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

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

FindElementsByClassName

  • IAndroidElementAPI[] FindElementsByClassName(string className)
    Finds all elements by class name.

    Parameters:

    • className — class name.

    Returns:
    Array of elements.

Example

var driver = instance.DroidInstance.AppiumDriver;

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

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

FindElementsByUiAutomator

  • IAndroidElementAPI[] FindElementsByUiAutomator(string uiSelector)
    Finds all elements via UiSelector.

    Parameters:

    • uiSelector — selector string.

    Returns:
    Array of elements.

Example

var driver = instance.DroidInstance.AppiumDriver;

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

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

FindElementsByXPath

  • IAndroidElementAPI[] FindElementsByXPath(string xpath)
    Finds all elements by XPath.

    Parameters:

    • xpath — XPath expression.

    Returns:
    Array of elements.

Example

var driver = instance.DroidInstance.AppiumDriver;

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

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

ScrollToElementByAccessibilityId

  • void ScrollToElementByAccessibilityId(string id, int maxSwipes)
    Scrolls the screen to an element by Accessibility ID.

    Parameters:

    • id — value of content-desc;
    • maxSwipes — maximum 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

ScrollToElementByClassName

  • void ScrollToElementByClassName(string className, int maxSwipes)
    Scrolls the screen to an element by class name.

    Parameters:

    • className — class name;
    • maxSwipes — maximum 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

ScrollToElementByUiAutomator

  • void ScrollToElementByUiAutomator(string uiSelector, int maxSwipes)
    Scrolls the screen to an element via UiSelector.

    Parameters:

    • uiSelector — selector string;
    • maxSwipes — maximum 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

GetScreenshot

  • string GetScreenshot()
    Takes a screenshot of the current device screen.

    Returns:
    Image as a Base64 string.


UpdateSettings

  • void UpdateSettings(string key, object value)
    Updates a single driver setting.

    Parameters:

    • key — setting name (e.g. Appium Settings API parameters);
    • value — new setting value.

Example

var driver = instance.DroidInstance.AppiumDriver;

driver.UpdateSettings("allowInvisibleElements", false);

  • void UpdateSettings(IEnumerable<KeyValuePair<string, object>> keyValuePairs)
    Bulk-updates driver settings.

    Parameters:

    • keyValuePairs — collection of key-value pairs to update multiple settings in one call.

Example

var driver = instance.DroidInstance.AppiumDriver;

var settings = new KeyValuePair<string, object>[]
{
new KeyValuePair<string, object>("allowInvisibleViewport", true),
new KeyValuePair<string, object>("allowInvisibleElements", false),
new KeyValuePair<string, object>("ignoreUnimportantViews", false),
};

driver.UpdateSettings(settings);