How to get last element based on a class

Ask general questions here.
alexander.tang
Posts: 2
Joined: Tue Jul 10, 2018 2:01 pm

How to get last element based on a class

Post by alexander.tang » Tue Jul 10, 2018 2:39 pm

Is there a way to get the last element based on a class?
Let say we have multiple div elements, I need to get the third one.
  • div[@class='modal fade in']
  • div[@class='modal-backdrop fade in']
  • div[@class='modal fade in']
  • div[@class='modal-backdrop fade in']
I've try the following path which is not working since the last div doesnt match the one in the path:

Code: Select all

/dom[@domain='localhost']/body/div[@class='modal fade in' and last()='True']

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

Re: How to get last element based on a class

Post by odklizec » Wed Jul 11, 2018 11:32 am

Hi,

Any chance you could post a Ranorex snapshot? With snapshot, it would be much easier for us to help you with the right xpath ;) Anyway, you can try this...

Code: Select all

/dom[@domain='localhost']/body/div[@class='modal fade in'][-1]
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

alexander.tang
Posts: 2
Joined: Tue Jul 10, 2018 2:01 pm

Re: How to get last element based on a class

Post by alexander.tang » Mon Jul 23, 2018 9:30 am

odklizec wrote:
Wed Jul 11, 2018 11:32 am
Hi,

Any chance you could post a Ranorex snapshot? With snapshot, it would be much easier for us to help you with the right xpath ;) Anyway, you can try this...

Code: Select all

/dom[@domain='localhost']/body/div[@class='modal fade in'][-1]
Thank you this is what I needed.

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

Re: How to get last element based on a class

Post by odklizec » Mon Jul 23, 2018 9:34 am

Hi,

Nice to hear that! ;)
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