Find preceding element in appium


#1

Hi have layout in android app like this

ListView
(0)RelativeLayout
(0)TextView:Tom
(1)TextView:OPEN
(2)TextView:1 [ id :conversations_row_message_count]
(1)RelativeLayout
(0)TextView:Jack
(1)TextView:OPEN
(2)TextView:2nd_place_medal:[ id :conversations_row_message_count]
(2)RelativeLayout
(0)TextView:Jack
(1)TextView:OPEN

I want to get preceding Text Views from the relative layout in which Text View with id " conversations_row_message_count " is present.
Below are the ways I have tried till now but nothing seems working for me

1. “//android.widget.TextView[contains(@resource-id,‘conversations_row_message_count’)]”;
**Resut : ** It gave me all the elements where TextView with id “conversations_row_message_count”.

2."//android.widget.TextView[contains(@resource-id,‘conversations_row_contact_name’)]/following-sibling::android.widget.TextView[contains(@resource-id,‘conversations_row_message_count’)]";
**Resut : ** It gave me no element as there are not following element

3."//android.widget.RelativeLayout//android.widget.TextView[contains(@resource-id,‘conversations_row_message_count’)]";
**Resut : ** It gave me all the elements with their but when I tried to print it’s class name attribute it throws error “An element could not be located on the page using the given search parameters.”

4."//android.widget.TextView[contains(@resource-id,‘conversations_row_message_count’)]/preceding-sibling::TextView";
**Resut : ** Tried to get preceding element but dint get any element.

Please suggest where I am going wrong