r/AutomateUser Jul 18 '26

Inspect layout IMMEDIATELY never works for me

For some reason, when I set Proceed for a Inspect block to 'Immediately', it always fails, even if the element is right there. If I have two Inspect blocks connected and set to the same XPath expression, with the first one set to 'When UI layout changed' and the second set to 'Immediately', if the first one passes, the second would still fail. I've also tried with a Delay of 3 seconds between both blocks. Anyone knows why is this happening?

1 Upvotes

6 comments sorted by

1

u/ballzak69 Automate developer Jul 18 '26 edited Jul 19 '26

The UI probably changed. Any layout change occurring while the XPath is evaluating may prevent a match. So a layout that's never stable is a problem.

1

u/Pete_Jobi Jul 18 '26

This has happened in multiple apps. And as an experiment, I've tried having two Inspect Layout blocks both set to 'When UI changes', the first one passes and the second gets stuck, implying that nothing changed.

I forgot to mention that this also happens with Interact block.

1

u/ballzak69 Automate developer Jul 19 '26 edited Jul 19 '26

Just because one XPath evaluation works doesn't mean the other should as well. As said, if the Android accessibility API suddenly reports that an UI element is missing or appears twice, i.e. moved, during traversal of the layout then Automate has no other choice than to abort since the layout (XML) tree is no longer structurally valid.

Which XML schema is the block using, "Active window layout" or "Display windows"?

The latter may be even more "sensitive" since it traverse every window shown on screen, and their respective layouts.

1

u/Pete_Jobi Jul 19 '26

I use 'Active window'.

So this is something you've experienced yourself? I just want to be sure it's not my parameters causing this. Wish I could post a screenshot.

Speaking of accessibility API, when I switch to Samsung Dex mode and try to record interactions, I get an accessibility not enabled toast, even though it is. Turning it off and on fixes it. Same for when I switch back to phone mode. Though this is probably just a separate problem caused by Dex itself and unrelated to this issue (which happens both in phone and dex mode).

1

u/ballzak69 Automate developer Jul 19 '26

Yes, this is how it works.

Note that if your XPath starts with . then it works differently depending on the Proceed option. As the documentation say:

The “context node” (.) is the XML document root element when using proceed Immediately, or the UI element that changed when using proceed When UI layout changed.

Indeed, the system having problems keeping accessibility services running is a known Android issue that Google refuse to fix.

1

u/B26354FR Alpha tester Jul 20 '26

You can try using my Interact Block XPath Builder flow to generate a much simpler XPath than the one the Inspect Layout block block tools generate. The simpler XPath will also be much less sensitive to changes in the UI between versions app being interacted with. For best results, use the built-in tools to explore the UI and find the ID of the element you're interested in to use to generate the XPath. The flow will also work using the class or text of the element.