Appium cannot get content-desc attribute data

In the example below, Appium can correctly find elements by class, but when we want to manipulate data based on each content-desc element, we see an error. Why can't we get the attribute for content-desc? Any advice is 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: the item cannot be located on the page using these search parameters. (WARNING: the server did not provide any stack information)

+5
source share
4 answers

Use "name"

property.getAttribute("name");

+15
source

A list of accepted attribute names can be found in boolean attrbutes and string attributes .

Logical Attributes:

  • switched on
  • verifiable
  • checked
  • interactive
  • focusable
  • focused
  • longClickable
  • to scroll
  • selected
  • is displayed

Suitable lines:

  • contentDescription
  • text
  • class name
  • RESOURCEID

I tested this using python bindings.

The credit goes to TikhomirovSergey in a github comment .

+1
source

try the following:

driver.findElement(By.AccessibilityID(""));

0
source

text OR descending content can be used as

 driver.findElement(By.xpath("//*[@text='Remove Contact']")) 

can be a user like

 driver.findElement(By.name("Remove Contact")) driver.findElement(By.xpath("//*[@content-desc='Remove Contact']")) 

can be used as

 driver.findElement(By.name("Remove Contact")) 
-2
source

Source: https://habr.com/ru/post/1203439/


All Articles