Using Location in xPath

Ask general questions here.
User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Using Location in xPath

Post by Aracknid » Thu Feb 14, 2013 7:28 pm

I'm using 3.3.5.

I need to wait until an IFrame's body loads up all the items within it. I wrote code that worked great for IE, but in FF and Chrome it does not work. So right now in IE I'm doing this:
MyBody = MyWebDoc.FindSingle(".//iframe[@id='MyID']/body[@valid='true'],120000)
I noticed in all browsers another way I could get it to work involving the Location attribute. The location in my case is always 8,8 until it is loaded, at which point it becomes 0,0.

I saw an example of RxPath using location for a button, and this example didn't use an "@" before the location, and I tried this in my code, but it never found the item even though the "location.x=0" is what is shown in Spy when it appears. Even in Spy itself, I can edit the Xpath and it will not find it.

So if I change my code to this:
MyBody = MyWebDoc.FindSingle(".//iframe[@id='MyID']/body[location.x=0],120000)
It doesn't find it.

In Spy, If I type this out, it always throws an "@" in front of the location attribute, and still doesn't find it.

Does this not work for body or web elements?

For reference, please see: http://www.ranorex.com/support/user-gui ... xpath.html
and look in the "attributes" section for this line:
/form/button[location.x=100]

Aracknid.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Using Location in xPath

Post by Support Team » Wed Feb 20, 2013 11:08 am

I think you are mixing up two functionalities in the RanoreXPath: One is using cascaded property/attribute names ("@items.count") and the other is location functions ("x()").
The example in the RanoreXPath documentation "location.x" tries to get the "location" attribute and immediately gets the "X" property of the returned value. This only works for some technologies (WinForms, Flex, Java).
What you actually meant is the "x()" or "cx()" functions that return the x coordinate (or relative x coordinate to the parent) of the element; see the "Functions" part in the RanoreXPath documentation.

So your RanoreXPath should work if you use the "x()" or "cx()" function instead of "location.x".
Aracknid wrote:In Spy, If I type this out, it always throws an "@" in front of the location attribute, and still doesn't find it.
The '@' can be omitted for attributes in a RanoreXPath, but it makes the path easier to read.

Regards,
Alex
Ranorex Team
.
Image