Solved

Find the positions of controls on Android

Posted on 2014-07-28
3
205 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This question got me thinking... (http://www.experts-exchange.com/questions/28707487/GLOBALS.html) Why shouldn't we use Globals? This is a simple question without a simple answer.  How do you explain these concepts to a programmer w…
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.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now