Combining attributes in an xpath

Ask general questions here.
Eamonn
Posts: 63
Joined: Wed Jul 16, 2014 9:30 am
Location: Dundalk, Ireland.

Combining attributes in an xpath

Post by Eamonn » Wed Oct 14, 2015 11:38 am

I have an element with the xpath ending: //div[#'myCarousel']/ol/li[2], this element has a class equal to 'active' and I can identify the element using the xpath: //div[#'myCarousel']/ol/li[@class='active']. However, I wish to identify the element by combining the attributes of 'Li' shown in both xpaths. Is it possible to identify the 'Li' element using the two Attribute Comparison sections i.e. index 2 in the General and @class='active' in the NativeWindow section?

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

Re: Combining attributes in an xpath

Post by odklizec » Wed Oct 14, 2015 12:05 pm

Hi,

If I understand you right, what you are looking for is this...
//div[#'myCarousel']/ol/li[@class='active'][2]
Hope this helps?
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

Eamonn
Posts: 63
Joined: Wed Jul 16, 2014 9:30 am
Location: Dundalk, Ireland.

Re: Combining attributes in an xpath

Post by Eamonn » Wed Oct 14, 2015 12:44 pm

Sorry, the suggested xpath does not find the element.

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

Re: Combining attributes in an xpath

Post by odklizec » Wed Oct 14, 2015 12:50 pm

Hi,

If you can find the element by index 2 and @class='active' attribute (if used separately), then spy should find the element also if the index and attribute are combined in the same xpath. Could you please post a Ranorex snapshot of the element in question?
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

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Combining attributes in an xpath

Post by Fergal » Wed Oct 14, 2015 1:11 pm

odklizec wrote:...li[@class='active'][2]...
Would changing that to "li[2][@class='active']" work? Could that path find the second "li" when it is active, rather than the second active "li"?

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

Re: Combining attributes in an xpath

Post by odklizec » Wed Oct 14, 2015 1:21 pm

Yeah, Fergal is probably right! I'm always mixing up the order of index and attributes in the xpath ;) This is why it's always better to post snapshot in support requests. One can quickly check the solution before posting it.
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

Eamonn
Posts: 63
Joined: Wed Jul 16, 2014 9:30 am
Location: Dundalk, Ireland.

Re: Combining attributes in an xpath

Post by Eamonn » Fri Oct 16, 2015 1:14 pm

Neither suggestions found the element. My question is; can I combine a general attribute such as a index of an element and a WebElement attribute such as @Class?

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

Re: Combining attributes in an xpath

Post by odklizec » Fri Oct 16, 2015 1:17 pm

Hi,

Basically, it should work the way we suggested. If it does not work, there is probably something else wrong in your xpath? It would be helpful, if you could post a Ranorex snapshot so we can test the xpath and attributes you provided.
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