how to create xpath expression

116 views
Skip to first unread message

Rakesh Raj

unread,
Sep 9, 2024, 4:29:21 AM9/9/24
to Automate for Android
Hello sir,
i am trying to create an xpath expression that clicks on the next element in the list every time the loop gets executed this is the xpath of the element :

/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[@android:id='@com.sgiggle.production:id/action_bar_root']/android.widget.FrameLayout[@android:id='@android:id/content']/android.widget.FrameLayout[@android:id='@com.sgiggle.production:id/container']/android.view.ViewGroup[@android:id='@com.sgiggle.production:id/coordinator']/android.widget.FrameLayout[@android:id='@com.sgiggle.production:id/design_bottom_sheet']/android.widget.LinearLayout[@android:id='@com.sgiggle.production:id/root_layout']/androidx.viewpager.widget.ViewPager[@android:id='@com.sgiggle.production:id/leaderboardViewPager']/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup[@android:id='@com.sgiggle.production:id/topLeaderBoardContent']/androidx.recyclerview.widget.RecyclerView[@android:id='@com.sgiggle.production:id/list']/android.view.ViewGroup[.//android.widget.TextView[@android:text='Saumit' and @android:id='@com.sgiggle.production:id/username']]

like in the first attacment

also with in this element which is the username there is another element which shows the number of points the user has gifted to me
xpath : /android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout[@android:id='@com.sgiggle.production:id/action_bar_root']/android.widget.FrameLayout[@android:id='@android:id/content']/android.widget.FrameLayout[@android:id='@com.sgiggle.production:id/container']/android.view.ViewGroup[@android:id='@com.sgiggle.production:id/coordinator']/android.widget.FrameLayout[@android:id='@com.sgiggle.production:id/design_bottom_sheet']/android.widget.LinearLayout[@android:id='@com.sgiggle.production:id/root_layout']/androidx.viewpager.widget.ViewPager[@android:id='@com.sgiggle.production:id/leaderboardViewPager']/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup[@android:id='@com.sgiggle.production:id/topLeaderBoardContent']/androidx.recyclerview.widget.RecyclerView[@android:id='@com.sgiggle.production:id/list']/android.view.ViewGroup/android.widget.TextView[@android:id='@com.sgiggle.production:id/points' and @android:text='107']

As shown in the secound attachment

I want to create an xpath expression that only clicks the username if the points sent by him to me is greater than 100


fr_149.jpg
fr_150.jpg

Henrik "The Developer" Lindqvist

unread,
Sep 9, 2024, 5:48:29 AM9/9/24
to Automate for Android
It's difficult to guess the XPath without seeing the layout XML, but try:

//androidx.recyclerview.widget.RecyclerView[@android:id='@com.sgiggle.production:id/list']/android.view.ViewGroup[.//android.widget.TextView[@android:id='@com.sgiggle.production:id/username' and @android:text='Saumit'] and .//android.widget.TextView[@android:id='@com.sgiggle.production:id/points' and number(@android:text) > 100]]

Henrik "The Developer" Lindqvist

unread,
Sep 9, 2024, 6:32:28 AM9/9/24
to Automate for Android
Try:

//androidx.recyclerview.widget.RecyclerView[@android:id='@com.sgiggle.production:id/list']/android.view.ViewGroup[{position}][.//android.widget.TextView[@android:id='@com.sgiggle.production:id/points' and number(@android:text) > 100] ]

On Monday, September 9, 2024 at 10:29:21 AM UTC+2 rakesh...@gmail.com wrote:
Message has been deleted

Rakesh Raj

unread,
Sep 9, 2024, 8:03:06 AM9/9/24
to Automate for Android
not working sir

Rakesh Raj

unread,
Sep 9, 2024, 8:09:48 AM9/9/24
to Automate for Android
//androidx.recyclerview.widget.RecyclerView[@android:id='@com.sgiggle.production:id/list']/android.view.ViewGroup[{position}]

this xpath is working and also looping through the elements but combining it with points is not working

Henrik "The Developer" Lindqvist

unread,
Sep 9, 2024, 10:28:00 AM9/9/24
to Automate for Android
As said, without seeing the layout XML it's impossible to tell why it's not working. Maybe it's because your "numbers" are formatted with comma as thousand separator, try:

//androidx.recyclerview.widget.RecyclerView[@android:id='@com.sgiggle.production:id/list']/android.view.ViewGroup[{position}][.//android.widget.TextView[@android:id='@com.sgiggle.production:id/points' and number(translate(@android:text, ',', '')) > 100] ]
Reply all
Reply to author
Forward
0 new messages