Element API
Please read the Material Usage Rules on this site.
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).
Text
string Text { get; }
Text content of the element.
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
Methods
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.
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
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
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
SendKeys
-
void SendKeys(string text)
Enters text character by character. More "realistic" input thanSendText.Parameters:
text— string to enter.
GetScreenshot
string GetScreenshot()
Takes a screenshot of the element's bounding area and returns it as a Base64 string.