Reputation: 71
I am using Appium version (1.4) on an Native android app
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.
Parent child select based on index
driver.findElement(By.xpath("//android.view.View[@index='2']/android.view.View[@index='0']"))
using class and content-desc
driver.findElement(By.xpath("//android.widget.Button[@content-desc='Your balance is: 100.00$ ']")).click();
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
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
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