Force Stop App

427 views
Skip to first unread message

Yule Angel

unread,
Jun 17, 2021, 11:44:25 PM6/17/21
to Automate
Hi, need help on the Xpath in the Interact Block.

I am using a Huawei phone.

Trying to create a flow to force stop an app. I can call up the app info page. I then use the Interact Block to record interaction. But it doesn't work.

Here is my input in the Interact Block

Action: Click (Android 4.1+)
Package: com.huawei.android.launcher
xPath expression: /android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[@android:id='@android:id/content']/android.widget.FrameLayout[@android:id='@com.huawei.android.launcher:id/drag_layer']/android.widget.FrameLayout[@android:id='@com.huawei.android.launcher:id/overview_panel_container']/android.widget.ScrollView[@android:id='@com.huawei.android.launcher:id/overview_panel']/android.widget.FrameLayout[@android:contentDescription='Settings App info']
Content:"FORCE STOP"

Please help.

narf...@gmail.com

unread,
Jun 18, 2021, 11:17:18 AM6/18/21
to Automate
Most of that XPath generated by the Interact block is unnecessary and might be causing trouble. You can try running this flow to generate a much simpler one which might work better:


(BTW, it doesn't need the Read sensitive log data permission.)

Run the 'XPath Builder' flow and give it that button text when prompted for a text description. (Just cancel the other dialogs.) The flow will generate an XPath for you and put it in your clipboard. Paste that into your Interact block and give it a try.

Hopefully, this will help!

Henrik "The Developer" Lindqvist

unread,
Jun 18, 2021, 1:59:36 PM6/18/21
to Automate
To open the app settings page, try using the App start block with action=Application details settings and Data URI=package:<package of app to kill>.
Then use the Interact block to simulate a click on the "force stop" button, which can be found by using the "Record interaction" button. Use the "search" icon if it doesn't record the Click event.

Yule Angel

unread,
Jun 18, 2021, 2:13:20 PM6/18/21
to Automate
I tried to record the interaction. but the floating field always disappears when I get to the app info page. There is no way I can record the interaction or search.

Yule Angel

unread,
Jun 18, 2021, 2:13:52 PM6/18/21
to Automate
Sorry, I'm not a very tech savvy person.

Generated this using the XPath Builder flow.

fn:reverse((.//*[(@android:contentDescription | @android:text[not(../@android:editable='true')])[fn:glob(., 'FORCE STOP')]])[1]/ancestor-or-self::*)

Do I copy the whole string into the xPath expression field?

If so, do I still need to keep the content in the package field?

Henrik "The Developer" Lindqvist

unread,
Jun 18, 2021, 2:26:45 PM6/18/21
to Automate
The "search" icon should work even if the button disappear, just drag it to the Force stop button.

Yule Angel

unread,
Jun 18, 2021, 2:43:38 PM6/18/21
to Automate
The last recorded interaction is always the page that I press to go to the setting info page.

Also doesn't work when using the search icon as the record interaction box disappears when you get to the FORCE STOP page.

Henrik "The Developer" Lindqvist

unread,
Jun 20, 2021, 1:51:29 PM6/20/21
to Automate
indeed, on some devices the "record interaction", or any overlay, is hidden when the system Settings is opened.
Then your only option is to write the XPath expression manually from looking at the inspected layout, e.g. .//android.widget.Button[@android:contentDescription='Force stop']

Yule Angel

unread,
Jun 20, 2021, 10:02:17 PM6/20/21
to Automate
Hi, I've input these variables in the Interact Block, but still doesn't work.

Proceed: Immediately
Action: Click
Package: com.android.settings
XPath expression: .//android.widget.Button[@android:contentDescription='Force stop']
Content: <left blank>

Is there anything else I should put in?

narf...@gmail.com

unread,
Jun 20, 2021, 10:07:50 PM6/20/21
to Automate
Henrik's example was just that; you'd need to analyze the XPath generated by the Interact block Record Interactions feature to see what the specific XPath element should be. Or, use my flow to generate it for you based on the element text ("Force stop") you give it.

Yule Angel

unread,
Jun 21, 2021, 4:23:12 AM6/21/21
to Automate
I generated the XPath using your flow.

fn:reverse((.//*[(@android:contentDescription | @android:text[not(../@android:editable='true')])[fn:glob(., 'FORCE STOP')]])[1]/ancestor-or-self::*)

So I just copy the whole path in the XPath Expression field?

narf...@gmail.com

unread,
Jun 21, 2021, 4:28:08 AM6/21/21
to Automate
Yep!

Henrik "The Developer" Lindqvist

unread,
Jun 21, 2021, 1:11:11 PM6/21/21
to Automate
The XPath expression was just an example, you need to Inspect layout and look for the Ui element, then adjust it accordingly.

Yule Angel

unread,
Jun 21, 2021, 11:04:04 PM6/21/21
to Automate
Thanks both. I've managed to get the flow to work! :)
Reply all
Reply to author
Forward
0 new messages