How to Check Which Element of Same Type is first

Class library usage, coding and language questions.
Deepak_Singh
Posts: 76
Joined: Fri Mar 14, 2014 2:37 pm

How to Check Which Element of Same Type is first

Post by Deepak_Singh » Fri Mar 28, 2014 6:23 am

Hi,
I am having an application in which there are few Radiobuttons at a paticular Page. Now i want to know there positions i.e I want to know that which is first and which is second and so on.
And I want to tell that which is to the right for example: Radio button1 and Radio button2 are there now how will I check that Radio Button1 is left to Radio Button2 or vice verca? :?:

For addtion will I be able to get there co-ordinates and store them? :?:

And is there a way to highlight an object during execution? :?:


Thanks In Advance.
Deepak
:D

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to Check Which Element of Same Type is first

Post by odklizec » Fri Mar 28, 2014 8:53 am

Hi,

I don't think there is a way to highlight the objects during playback? But I never looked for such option so I could be wrong about this ;)

As for getting object coordinates, you can use something like this:
Ranorex.Button btnStart = "/button[@accessiblename='OK']"; 
	int xPos = btnStart.ScreenRectangle.X;
	int yPos = btnStart.ScreenRectangle.Y;
	System.Diagnostics.Debug.WriteLine("xPos: " + xPos.ToString() + "\n" + "yPos: " + yPos.ToString() + "\n");
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: How to Check Which Element of Same Type is first

Post by mzperix » Fri Mar 28, 2014 9:05 am

Hi,

Highlighting is possible since Ranorex 4.1: http://www.ranorex.com/forum/highlight- ... t2623.html

Best Regards
Zoltán

Deepak_Singh
Posts: 76
Joined: Fri Mar 14, 2014 2:37 pm

Re: How to Check Which Element of Same Type is first

Post by Deepak_Singh » Mon Mar 31, 2014 3:09 am

Hi,
Thanks both of you for ur help. Helped me a lot...

But i would like to add that what if its not a button.

Lets say Its a text box or something like a rectangle then how will i get the x and y coordinates of all the 4 points :?:
And after getting coordinates how will we compare in such a way that i can say that this rectangle is above this rectangle.
like username field is above password field.

can you provide me a little help...


Thanks in advance,
Deepak :D

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to Check Which Element of Same Type is first

Post by odklizec » Mon Mar 31, 2014 8:53 am

Hi,

The same as X,Y coordinates, you can get also Width and Height of required element. This way you can get entire screen rectangle. Now if you need separate x/x values for each rectangle corner, then all you need to do is to calculate them using x/y and width/height values:
x_y.png
Hope this helps?
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: How to Check Which Element of Same Type is first

Post by mzperix » Mon Mar 31, 2014 10:35 am

Hi Deepak,

Every element, you create in ranorex has the ScreenRectangle.X and ScreenRectangle.Y and also the
ScreenRectangle.Width and ScreenRectangle.Height proprties. With these information, you can calculate these elements relative position.

Based on odklizec comment, this should be the procedure to check for two elements position:
1. Get the first elements' X,Y,Width and Height properties
2. Get the second elements' X,Y,Width and Height properties
3. Compare the coordinates.

For example, if we want to see if element1 is above element2, the elements are starting at the same horizontal position and they have the same width.

Code: Select all


//get the info on element1
Ranorex.Element element1 = "/input[@id='username']";
    int xPos_1 = element1.ScreenRectangle.X;
    int yPos_1 = element1.ScreenRectangle.Y;
    int width_1 = element1.ScreenRectangle.Width;
    int height_1= element1.ScreenRectangle.Height;

//get the info on element2
Ranorex.Element element2 = "/input[@id='password']";
    int xPos_2 = element1.ScreenRectangle.X;
    int yPos_2 = element1.ScreenRectangle.Y;
    int width_2 = element1.ScreenRectangle.Width;
    int height_2= element1.ScreenRectangle.Height;

//the following boolean expressions can be used
//the check if element1 is above element2
bool is_above = ((yPos_1+width_1) > yPos_2);
//the check if element1 and element2 has the same starting position, and the same width
bool is_in_good_shape = ((xPos_1 == xPos_2) && (width_1 == width_2));
Hope this helps,
Zoltán Major

Ps1: I used the Ranorex API reference to get the info I needed: http://www.ranorex.com/Documentation/Ranorex/

For everthing else, there is .NETreference: http://msdn.microsoft.com/en-us/library/1zk39146

PS2: I used the most generic, element class to create the adapter for the input field. But I suggest to always try to use the proper element adapter, like the InputTag in.

Deepak_Singh
Posts: 76
Joined: Fri Mar 14, 2014 2:37 pm

Re: How to Check Which Element of Same Type is first

Post by Deepak_Singh » Tue Apr 01, 2014 3:51 am

Thanks a lot, You guys rock.
:D