Prasad Madge
Prasad Madge

Reputation: 71

Appium , not able to read text having content desc and index on an Android native app

I am using Appium version (1.4) on an Native android app

enter image description here

I want to read the text show in red box. I am not able to locate the element based on content-desc and index too.

These are some of the code which I have tried but its failing to locate it.

  1. Parent child select based on index

    driver.findElement(By.xpath("//android.view.View[@index='2']/android.view.View[@index='0']"))
    
  2. using class and content-desc

    driver.findElement(By.xpath("//android.widget.Button[@content-desc='Your balance is: 100.00$ ']")).click();
    
  3. Using class and iterating through a list

    List<WebElement> arrayOfProperties2 = driver.findElements(By.xpath("//android.view.View"));
    System.out.println("Found arrayOfProperties2 total: "+ arrayOfProperties2.size());
    

The size of the list comes zero in this case.

The scenario is to read the text shown since the balance amount changes .

I am able to locate other elements on the activity but not the above one.

Upvotes: 0

Views: 2308

Answers (2)

noor
noor

Reputation: 3004

try by using the below xpath:

//*[@class = 'android.view.View' and contains(@content-desc,'Your balance is')]

hope this will help you and let me know what happens.

Upvotes: 2

Diego Torres Milano
Diego Torres Milano

Reputation: 69208

It would be fairly easy using AndroidViewClient/culebra.

Start Culebra GUI using

culebra --use-regexps --gui

and the generated script will contain a line like

no_id25 = vc.findViewWithContentDescriptionOrRaise(re.compile(u'''Your balance is: 100.00$ Heading'''))

change it to a more suitable regex

no_id25 = vc.findViewWithContentDescriptionOrRaise(re.compile(u'''Your balance is: \d+.\d+\$ Heading'''))

and it should match your View.

Strictly speaking, if you are not going to interact and just want to match the View you may run it without --gui.

Upvotes: -1

Related Questions