Skip to main content

Element API


Description

IAndroidElementAPI

This interface allows you to manage user interface elements in Android apps. You use it to perform various actions on elements found using the IAppiumDriverAPI interface methods.

Properties

  • Element's id property value
string Id { get; }
  • Element's text property value
string Text { get; }

Examples:

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 id = de.Id; // Get the Id property value
var text = de.Text; // Get the text property value

Methods

Get an element's property value

string GetAttribute(string name)

Parameters:

string name // Name of the property you want to get.

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" property value
var text = de.GetAttribute("text"); // Get the "text" property value

Click the found element

void Click()

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 an element's value (like input text)

void Clear()

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

Enter text into the element's field

void SendText(string text)

Parameters:

string text  // The value you want 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

Enter special characters

void SendKeys(string text)

Parameters:

string text  // Special characters you want to enter.