Combining attributes in an xpath
Combining attributes in an xpath
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?
Re: Combining attributes in an xpath
Hi,
If I understand you right, what you are looking for is this...
If I understand you right, what you are looking for is this...
Hope this helps?//div[#'myCarousel']/ol/li[@class='active'][2]
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: Combining attributes in an xpath
Sorry, the suggested xpath does not find the element.
Re: Combining attributes in an xpath
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?
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 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
-
- Certified Professional
- Posts: 455
- Joined: Tue Feb 18, 2014 2:14 pm
- Location: Co Louth, Ireland
- Contact:
Re: Combining attributes in an xpath
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"?odklizec wrote:...li[@class='active'][2]...
Re: Combining attributes in an xpath
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 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
Re: Combining attributes in an xpath
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?
Re: Combining attributes in an xpath
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.
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 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