Page 1 of 1

Combining attributes in an xpath

Posted: Wed Oct 14, 2015 11:38 am
by Eamonn
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

Posted: Wed Oct 14, 2015 12:05 pm
by odklizec
Hi,

If I understand you right, what you are looking for is this...
//div[#'myCarousel']/ol/li[@class='active'][2]
Hope this helps?

Re: Combining attributes in an xpath

Posted: Wed Oct 14, 2015 12:44 pm
by Eamonn
Sorry, the suggested xpath does not find the element.

Re: Combining attributes in an xpath

Posted: Wed Oct 14, 2015 12:50 pm
by odklizec
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?

Re: Combining attributes in an xpath

Posted: Wed Oct 14, 2015 1:11 pm
by Fergal
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"?

Re: Combining attributes in an xpath

Posted: Wed Oct 14, 2015 1:21 pm
by odklizec
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.

Re: Combining attributes in an xpath

Posted: Fri Oct 16, 2015 1:14 pm
by Eamonn
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

Posted: Fri Oct 16, 2015 1:17 pm
by odklizec
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.