Inspect change to click - workaround

376 views
Skip to first unread message

Towe

unread,
Nov 23, 2021, 1:32:36 PM11/23/21
to Automate
Hi

When struggling to find the right element, I see that many people suggest the "recorded interactions" feature using the "inspect" action, importing the xpath expression and then changing the action to click.

I did the above testing the inspect ui element first to ensure it was present, that worked.

I then changed the action from inspect to click, however it did not click.

Does anyone have suggestions as to why this is happening?

The xpath expression I am working with is:

"/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[@android:id='@com.acomi.acomi:id/action_bar_root']/android.widget.FrameLayout[@android:id='@android:id/content']/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.TextView[@android:text='BUY NOW']"


I appreciate any help/suggestions with this as its driving me mad trying to work out where its going wrong.

Thanks.

Towe

unread,
Nov 23, 2021, 1:36:22 PM11/23/21
to Automate
This is using the interact block if it wasn't already apparent.

Henrik "The Developer" Lindqvist

unread,
Nov 24, 2021, 7:21:17 AM11/24/21
to Automate
Try using:
.//android.widget.TextView[@android:text='BUY NOW']
or
.//android.widget.TextView[@android:text='BUY NOW']/..

Towe

unread,
Nov 24, 2021, 7:36:45 AM11/24/21
to Automate
Hi Henrik,

Thank you for your suggestions. I have tried what you said, unfortunately this did not resolve my issue.

I've since hooked up my android and app to UI Automator Viewer and can see that the node details of what I want to click is set to "clickable: false". Does this mean that automate will never be able to use the click action on this element? Are there any workarounds. I kinda want to avoid interact touch if I can.

Shari Shark

unread,
Nov 24, 2021, 7:39:57 AM11/24/21
to automa...@googlegroups.com
You might want to try  //android.widget.TextView[@android:text='BUY NOW']/ancestor-or-self::*

Likely the node is not clickable, but somewhere along the hierarchy is. 

--
You received this message because you are subscribed to the Google Groups "Automate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automate-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/automate-user/0ee38b1b-c3ab-4b46-b7a3-3a0ac584517an%40googlegroups.com.

Towe

unread,
Nov 24, 2021, 8:19:05 AM11/24/21
to Automate
Bingo! That did the trick! Thank you genius!

Towe

unread,
Nov 30, 2021, 12:08:12 PM11/30/21
to Automate
After further testing it seems that clicking too many nodes is causing issues. Is there anyway to click just the parent of TextView[@android:text='BUY NOW']

On Wednesday, 24 November 2021 at 12:39:57 UTC Shari Shark wrote:

Towe

unread,
Nov 30, 2021, 12:08:38 PM11/30/21
to Automate
After further testing it seems that clicking too many nodes is causing issues. Is there anyway to click just the parent of TextView[@android:text='BUY NOW']

Henrik "The Developer" Lindqvist

unread,
Nov 30, 2021, 12:41:41 PM11/30/21
to Automate
.//android.widget.TextView[@android:text='BUY NOW']/..

Shari Shark

unread,
Dec 1, 2021, 6:35:59 AM12/1/21
to automa...@googlegroups.com
Then use parent::* instead of ancestor::*

However, without knowing the entire xml, the click might not work. As parent is only the direct node.

Also, it shouldn't be the case of too many clicks, as each iteration will only click 1 element. What's more likely is that there are multiple elements with the same xpath. In order to fix this, you need to narrow down the xpath selection.

Towe

unread,
Dec 2, 2021, 4:49:00 AM12/2/21
to Automate
"/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout[@android:id='@com.acomi.acomi:id/action_bar_root']/android.widget.FrameLayout[@android:id='@android:id/content']/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.TextView[@android:text='BUY NOW']"

I've bold the the area of the xpath which is clickable, however there are 3 other classes with the same name on the same level/hierarchy, how can I specify? Can I tell it to use the 4th one or can I use an index value? UI Automate shows the index value of the particular node as 7.

Henrik "The Developer" Lindqvist

unread,
Dec 2, 2021, 9:48:55 AM12/2/21
to Automate
Try:
fn:reverse((.//android.widget.TextView[@android:text='BUY NOW'])[1]/ancestor-or-self::*)

Towe

unread,
Dec 3, 2021, 4:55:03 AM12/3/21
to Automate
Thank you for all your help so far.

Is there a workaround/modification to essentially not search for just 6.99, but to search for a value between 6.00 and 8.00?
XPATH:  "//android.widget.TextView[@android:text='6.99']/ancestor::*"

Shari Shark

unread,
Dec 3, 2021, 11:32:30 AM12/3/21
to automa...@googlegroups.com
You can try //android.widget.TextView[@android:text>='6' and @android:text<='8']/ancestor::*



Towe

unread,
Dec 3, 2021, 11:59:25 AM12/3/21
to Automate
Perfect, thank you!

aspen thedon

unread,
Jan 8, 2022, 12:08:42 PM1/8/22
to Automate
Did this work for you? @towe
Reply all
Reply to author
Forward
0 new messages