Solved

Find the positions of controls on Android

Posted on 2014-07-28
3
215 Views
Last Modified: 2014-07-31
Greetings,
I am working on an automated test framework which should perform some tests on screen by clicking some controls on the
by mean of a screens invoking 'input tap x y', with x,y being the coordinates of the center of the command.
Does anyone have any suggestions on how I can do this ?

Regards,
r
0
Comment
Question by:rjorge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Molnar István
ID: 40224463
iterate through all the controls:

int location[] = new int[2];
for(int i=0; i < layout.getChildCount(); i++) {
    View v = layout.childAt(i);
    if (v instanceof Button) {
        v.getLocationOnScreen(location); 
    }else
    if (v instanceof EditText) {
        ((EditText)v).getLocationOnScreen(location); 
    }
}

Open in new window

in location array you will get the location of button,edittext, etc. , after that  you can show on the screen the coords

hope i understand correctly, your question
ps: sorry, but i didn't have time to test the code, but i think you get the idea
0
 

Author Comment

by:rjorge
ID: 40224501
Hi Molnar,
thanks for the reply. My intention is to (preferably) be able to do it from outside the running app. That way, I don't need to modify it.
Anny suggestion ?
0
 
LVL 13

Accepted Solution

by:
Molnar István earned 500 total points
ID: 40226888
if you want to test an application, you can use an UI Tester tool called UI Automator Viewer from Google:
UI Tester

with this you can test your application that is running from mobile, it shows you on the right side the coordinates and what you clicked.

for example this application , uses screenshots with some features (it has inspect element)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
If you use the Google Now Launcher, as an aftermarket add on, have a Samsung Note 5 and are worried about power consumption be wary of using the ultra power saving mode.  Here is what happened to me when I made the mistake of trying this out...
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question