tag:blogger.com,1999:blog-2914260921790421881.post6531348947994381323..comments2024-03-14T02:27:56.792-07:00Comments on Mr. Selenium: Xpath In All It's GloryBrian Kitchenerhttp://www.blogger.com/profile/12481074482396992611noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-2914260921790421881.post-79114385477417506992014-04-15T22:56:03.716-07:002014-04-15T22:56:03.716-07:00Some additional XPath examples that you don't ...Some additional XPath examples that you don't get with CSS selectors:<br /><br />(//someXPathThatReturnsMultipleMatches)[n]<br /><br />where it returns the nth match in the set of elements defined by Xpath within parenthesis<br /><br />//div[span[a[@title='foo']]] <br /><br />where we match & return the div (not the hyperlink) which contains a span which in turn contains a hyperlink with title of "foo". Another example to what you already posted.<br /><br />//div[@class='some value']/following-sibling::div[5]<br /><br />or <br /><br />//div[@class='some value']/preceding-sibling::div[5]<br /><br />which return the 5th sibling div before or after the div with the given class, that is the indicated indexed sibling div that has same parent as the div with the specified class<br /><br />And from what you pointed out in http://mrselenium.blogspot.com/2011/01/quick-xpath-for-dummies.html<br /><br />contains() and the ".." parent are very useful features of XPath.<br /><br />Out of all that I mention here in this comment, following-sibling or just "following" is the only thing CSS does offer. contains() is only partially offered as a pseudo CSS selector/feature, which generally means use of jQuery or Sizzle library to use it, as it is not part of native CSS3.Anonymousnoreply@blogger.com