Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get android element's 'resource id' and 'content description' attributes value in appium java?

I wanted to get resource id and content description of android elements at runtime.

i tried this:

myElement.getAttribute("resource-id")
myElement.getAttribute("content-desc")

but getting error as "this element does not have the resource-id attribute".

Is there any way to get this ?

like image 736
Chhagan Mathuriya Avatar asked Nov 17 '14 09:11

Chhagan Mathuriya


People also ask

How do I find my resource ID in Appium?

Syntax: driver. findElement(By.id(“resource-id Value”));

How do I get all the elements in Appium?

You can use the find_elements/findElements call provided by the appium driver to find all elements of a particular type (resource-id, class, etc), Once you have the elements, you can query each one to obtain the desired attributes or properties.

Can we use Elementid in Appium?

It can be used to find any element in the XML structure available to Appium. This means that even if an element has no ID or Name, it can still be located with XPath.


3 Answers

According to this post, the way to get "content-desc" is to use myElement.getAttribute("name").

like image 190
etxalpo Avatar answered Oct 05 '22 23:10

etxalpo


for resource-id use: webElement.getAttribute("resourceId")

like image 36
Ryan Avatar answered Oct 05 '22 23:10

Ryan


To get content-desc use:

myElement.getAttribute("contentDescription")

like image 37
zsts Avatar answered Oct 05 '22 23:10

zsts