Solved

Find the positions of controls on Android

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Often, people trade privacy and security for convenience. However in today's concrete jungle, this is an extremely foolish decision considering the vast amount of technologies being used against consumer interest. First off, I won't waste any time e…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.
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…

733 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