How to get coordinates for an object ?

Ask general questions here.
rastek
Posts: 185
Joined: Wed Aug 06, 2014 12:00 pm

How to get coordinates for an object ?

Post by rastek » Mon Dec 15, 2014 3:25 pm

Hi

I need coordinates for some objects, but when I spy on objects I cant not see anything for coordinates.

Is there a way for this in Ranorex ?

Thank,
Rastek.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to get coordinates for an object ?

Post by krstcs » Mon Dec 15, 2014 3:36 pm

Use the repo object's element location or screenlocation properties. Location is relative to the parent element, while screenlocation is relative to the whole screen.

Code: Select all

MyRepoObject.Element.Location.X
MyRepoObject.Element.Location.Y

MyRepoObject.Element.ScreenLocation.X
MyRepoObject.Element.ScreenLocation.Y
Shortcuts usually aren't...

ViMac
Posts: 5
Joined: Fri Jan 09, 2015 4:46 am

Re: How to get coordinates for an object ?

Post by ViMac » Mon Jan 12, 2015 8:58 am

Could you help me, please?
code:

Code: Select all

gridTravelOptRet.Element.Location.X;
gridTravelOptRet.Element.Location.Y;
gridTravelOptRet.Element.ScreenLocation.X;
gridTravelOptRet.Element.ScreenLocation.Y;
Error:
only assignment call increment decrement await and new object expressions can be used as a statement.


Please tell me how to write the code that does it right?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to get coordinates for an object ?

Post by Ciege » Mon Jan 12, 2015 4:12 pm

You need to set the value of a variable to the result of the element information...

Code: Select all

int locationX = gridTravelOptRet.Element.Location.X;
int locationY = gridTravelOptRet.Element.Location.Y;
int screenLocationX = gridTravelOptRet.Element.ScreenLocation.X;
int ScreenLocationY = gridTravelOptRet.Element.ScreenLocation.Y;
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

ViMac
Posts: 5
Joined: Fri Jan 09, 2015 4:46 am

Re: How to get coordinates for an object ?

Post by ViMac » Tue Jan 20, 2015 10:26 am

You just right, but I can not locate the object with the parameters which. Because that are the coordinates of the screen, each screen has different coordinates.
I still have no solution to the problem when the object value changes over timer and do not follow a rule. Please, Could you help me?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to get coordinates for an object ?

Post by Ciege » Tue Jan 20, 2015 5:39 pm

I'm not sure what issue you are having now. Can you be a little more clear?
Are you wondering how to find the location of an object on different screens? You will need to get that at runtime when you visit that screen. If the "object values change overtime" I assume you mean the object moves and is never in the same place twice. In that case, again, you need to check the location of the object at runtime, you cannot store that value and expect it to work the same each and every time.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

ViMac
Posts: 5
Joined: Fri Jan 09, 2015 4:46 am

Re: How to get coordinates for an object ?

Post by ViMac » Wed Jan 21, 2015 4:45 am

My issue:
To day, 01-21-2015 .To begin creating a reservation with:
Form "FindingFlights"
[*]Depart date: +2 date compare to now date.
[*]Return date: +4 date compare to now date.
Form "SelectingFlights"
[*]Depart: select an object with value 16,U,O
[*]Return: select an object with value 21,U,O
But date 01-22-2015 I run again, that value has changes. I am wondering how to locate an object of "SelectingFlights" form. :?:
Please,let me know any question for you to better my problem.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to get coordinates for an object ?

Post by Support Team » Tue Jan 27, 2015 10:20 am

Hi ViMac,

It would help a log if you could post a Ranorex Snapshot from your application and a detailed description. If you have already a Ranorex Solution it would also be great if you could provide your solution.
Unfortunately it is very difficult to help you solving your issue with the given information.

Regards,
Bernhard

ViMac
Posts: 5
Joined: Fri Jan 09, 2015 4:46 am

Re: How to get coordinates for an object ?

Post by ViMac » Thu Feb 05, 2015 9:21 am

The problem I am having is that the value of the option changes through each day (attached below). I would like to locate and select one of them, but the option to change every day, it's not supposed to change. Suddenly, I have a solution is to use the function if .... else.
EX:
var gridTravelOptDep = repo.CMAReservationsSiteSearchFlights1.GridTravelOptDep;
if(gridTravelOptDep.Value =="6,U,O"){
gridTravelOptDep.Focus();
gridTravelOptDep.Click();
}
else if(gridTravelOptDep.Value =="7,U,O"){
gridTravelOptDep.Focus();
gridTravelOptDep.Click();
}
else if(gridTravelOptDep.Value =="10,R,O"){
gridTravelOptDep.Focus();
gridTravelOptDep.Click();
}
Please advise if that solution is okay?
You do not have the required permissions to view the files attached to this post.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to get coordinates for an object ?

Post by Ciege » Thu Feb 05, 2015 10:31 pm

It seems to me you time would be best spent with your dev team to determine what the values mean, why and when they change so that you can accurately code for the different values of the radio buttons. Blindly coding a bunch of if statements is not a reliable solution. What if you didn't code for the right value? What if multiple values appear that you have if's for?
In my not so humble opinion, you really should spend some time understanding how your AUT works so you know how to test it.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...