Identify element without ID

Ask general questions here.
Alena
Posts: 20
Joined: Fri Feb 22, 2013 7:50 pm

Identify element without ID

Post by Alena » Thu Jun 20, 2013 4:54 pm

Hi all!
I have a web-page consisting of multiple elements div[#'blogEntry']. They don't have unique ID's but I need to choose the first and the last elements.
I was able to create a Rxpath to choose the first one (its RxPath is shown on png attached). Though it's exactly the same as the last element's path. When I track the last element with Spy, it finds the path but if I click Enter on this path, then right-click on identified element and choose Highlight element, Spy shows the first one again.
I can see that ChildIndex and ScreenLocation (second argument) change from entry to entry (and for the last blogEntry their values are 62 and 3516 respectively but these numbers will change for another page,they can't be hardcoded) but they're disabled and I can't operate any of those attributes.
Maybe, some regular expressions? functions like last()? I couldn't find anything useful in http://www.ranorex.com/support/user-gui ... xpath.html though this page helps a lot in other cases.
Please, help me to create unique paths for both cases.

Thanks,
Alena.
Attachments
SpyBlogEntryMult.png
SpyBlogEntryMult.png (145.26 KiB) Viewed 1151 times

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

Re: Identify element without ID

Post by Support Team » Fri Jun 21, 2013 2:20 pm

Hello,

Have you already tried the following path to get the last div tag?

Code: Select all

/dom[@domain='yourDomain']//div[#'blogEntry'][-1]
Regards,
Markus (T)
.
Image

Alena
Posts: 20
Joined: Fri Feb 22, 2013 7:50 pm

Re: Identify element without ID

Post by Alena » Tue Jun 25, 2013 8:16 pm

I tried this method as well but it takes enormous amount of time to find an element, so I hoped maybe something faster and easier is available which I don't know about.
In another part of my project, usually up to 6-8 validation points are checked per second, while here it takes up to 15-17 seconds for this single element to find, I guess, because there can be 40-50 [blogEntry] divs on a page.

And you have a mistake in that line of code. It should be either [@id='blogEntry'] or [#'blogEntry'] but not both @# :)

Thanks anyway Markus!

Alena.

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

Re: Identify element without ID

Post by Support Team » Wed Jun 26, 2013 2:58 pm

Hello Alena,

In general, searching for an element by a unique ID is quite fast.
Unfortunately, it seems that in your application the same ID is used for several elements (not unique).
This would outweighs the performance benefit for unique IDs.

You could try to extend the RxPath by adding the containers and elements in between.
Instead of the shortened path, you could try to extend it similar to the following path:

Code: Select all

/dom[@domain='yourDomain']/body/div[#'page']/div/div[#'content']/div[@id='blogEntry'][-1]
Regards,
Markus (T)
.
Image