Detecting text at specific location

Post your questions and help other users.

Moderator: Martin

Post Reply
TheUnknownBuffalo
Posts: 38
Joined: 09 Aug 2017 07:19

Detecting text at specific location

Post by TheUnknownBuffalo » 10 Oct 2017 13:25

Not as easy as it sounds, I've got an app that preloads text at an event, and then scrolls it down on some kind of transparent layer at stops at a certain location.

I've tried a UI matchglob *, and AM detects it before it lands at the final location, but I need it detected at the specific location otherwise it's unclickable. I also tried x,y location, but that doesn't seem to work either.

What else should I try?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Detecting text at specific location

Post by Desmanto » 10 Oct 2017 16:00

You want automagic to wait until the clickable button appear right? Use Overlay control to find the id of that clickable element. You can then check for its existence.

Example the element is com.xyz/OKButton, add a Control UI after the UI event.

Code: Select all

while(NOT existsElementById(com.xyz/OKButton))
  sleep(200);

clickById(com.xyz/OKButton);
Actually the UI event delay about half seconds before it is triggered, so your app maybe load longer than half second causing the problem. By using sleep when it is not detecting the OKButton, you will ensure the flow wait until it found the button before clicking it.

If your button doesn't have element, you have to use getTextInActiveWindow() and check if the text contains the text indicating the final location. Example, the clickable text is "end of line"

Code: Select all

while(NOT contains(getTextInActiveWindow(), "end of line"))
  sleep(200);

click("end of line");
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

TheUnknownBuffalo
Posts: 38
Joined: 09 Aug 2017 07:19

Re: Detecting text at specific location

Post by TheUnknownBuffalo » 10 Oct 2017 17:55

Hi Desmanto

That's what my current code looks like
It's not a button but text, I've grabbed it by the overlay control to get the ID. It seems the text is pre-loaded in the background of the screen somehow before actually displaying it in the foreground

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Detecting text at specific location

Post by Desmanto » 11 Oct 2017 02:50

How if you just set sleep for 5 seconds? Waiting until the text loaded up completely. And what is the result of the getTextInActiveWindow(), did it contain the text you wanna look for? If you can put some screenshot of the loading progress and the finished loaded one, it will be better.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply