Page 1 of 1

Identify element without ID

Posted: Thu Jun 20, 2013 4:54 pm
by Alena
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.

Re: Identify element without ID

Posted: Fri Jun 21, 2013 2:20 pm
by Support Team
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)

Re: Identify element without ID

Posted: Tue Jun 25, 2013 8:16 pm
by Alena
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.

Re: Identify element without ID

Posted: Wed Jun 26, 2013 2:58 pm
by Support Team
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)