Java – Appium unable to get “content-desc” attribute data

androidappiumjava

In the below case, Appium is correctly able to locate elements by class, but when we want to manipulate the data based on each element's content-desc we see an error. Why can't we get attribute for content-desc?
Any advice appreciated.

    List<WebElement> arrayOfProperties2 = driver.findElementsByClassName("android.view.View");
    List<WebElement> propertyMarkerEle = new ArrayList<>();

    System.out.println("Found arrayOfProperties2 total: "+ arrayOfProperties2.size());

    for (WebElement property : arrayOfProperties2){
        String contentDesc = property.getAttribute("content-desc");
        if (contentDesc.contains("property"))
            propertyMarkerEle.add(property);

Error: Found arrayOfProperties2 total: 32
org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING: The
server did not provide any stacktrace information)

Best Answer

Use "name"

property.getAttribute("name");

Related Topic