Skip to main content

Element API

Description​

IAndroidElementAPI represents an Android UI element in ZennoDroid (via Appium). Provides properties and methods for retrieving element information and interacting with it.

Properties​

Id​

  • string Id { get; }
    Unique element identifier (GUID).

IsDisplayed​

  • bool IsDisplayed { get; }
    Indicates whether the element is currently visible on screen.

Rectangle​

  • Rectangle Rectangle { get; }
    Element geometry (position and size) in screen coordinates.

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");

string id = de.Id; // Get the Id property value
string text = de.Text; // Get the Text property value
bool isDisplayed = de.IsDisplayed; // Get the IsDisplayed property value
Rectangle rectangle = de.Rectangle; // Get the Rectangle property value

Text​

  • string Text { get; }
    Text content of the element.

Methods​

Clear​

  • void Clear()
    Clears the element's content (typically a text field).

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.Clear(); // Clear the element's value

Click​

  • void Click()
    Clicks 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 on the element

GetAttribute​

  • string GetAttribute(string name)
    Returns the value of the specified element attribute (e.g. content-desc, class, checked, etc.).

    Parameters:

    • name — attribute name.

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");

var bounds = de.GetAttribute("bounds"); // Get the "bounds" attribute value
var text = de.GetAttribute("text"); // Get the "text" attribute value

GetBooleanAttribute​

  • bool GetBooleanAttribute(string name)
    Returns a boolean attribute value (e.g. enabled, clickable, checked).

    Parameters:

    • name — attribute name.

Example​

var driver = instance.DroidInstance.AppiumDriver;

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

bool clickable = de.GetBooleanAttribute("clickable"); // Whether the element can be clicked
bool enabled = de.GetBooleanAttribute("enabled"); // Whether the element is enabled

GetScreenshot​

  • string GetScreenshot()
    Takes a screenshot of the element's bounding area and returns it as a Base64 string.

Example​

var driver = instance.DroidInstance.AppiumDriver;

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

var data = Convert.FromBase64String(de.GetScreenshot()); // Screenshot of the element's area
using (var ms = new MemoryStream(data))
using (var bmp = new Bitmap(ms))
bmp.Save(project.Path + "element.png");

SendKeys​

  • void SendKeys(string text)
    Enters text character by character. More "realistic" input than SendText.

    Parameters:

    • text — string to enter.

Example​

var driver = instance.DroidInstance.AppiumDriver;

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

de.SendKeys("ZennoDroid"); // Send text to the element

SendText​

  • void SendText(string text)
    Enters text into the element.

    Parameters:

    • text — text to enter.

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.SendText("Hello world!"); // Enter text into the element's field