How to select specified node within Xpath node sets by index with Selenium?

This is a FAQ: //someName[3] means: all someName elements in the document, that are the third someName child of their parent — there may be many such elements. What you want is exactly the 3rd someName element: (//someName)[3] Explanation: the [] has a higher precedence (priority) than //. Remember always to put expressions of the … Read more

XPath – Selecting elements that equal a value

The XPath spec. defines the string value of an element as the concatenation (in document order) of all of its text-node descendents. This explains the “strange results”. “Better” results can be obtained using the expressions below: //*[text() = ‘qwerty’] The above selects every element in the document that has at least one text-node child with … Read more

XPath OR operator for different nodes

All title nodes with zipcode or book node as parent: Version 1: //title[parent::zipcode|parent::book] Version 2: //bookstore/book/title|//bookstore/city/zipcode/title Version 3: (results are sorted based on source data rather than the order of book then zipcode) //title[../../../*[book] or ../../../../*[city/zipcode]] or – used within true/false – a Boolean operator in xpath | – a Union operator in xpath that … Read more

How to select the first element with a specific attribute using XPath

Use: (/bookstore/book[@location=’US’])[1] This will first get the book elements with the location attribute equal to ‘US’. Then it will select the first node from that set. Note the use of parentheses, which are required by some implementations. Note, this is not the same as /bookstore/book[1][@location=’US’] unless the first element also happens to have that location … Read more

How can I match on an attribute that contains a certain string?

Here’s an example that finds div elements whose className contains atag: //div[contains(@class, ‘atag’)] Here’s an example that finds div elements whose className contains atag and btag: //div[contains(@class, ‘atag’) and contains(@class ,’btag’)] However, it will also find partial matches like class=”catag bobtag”. If you don’t want partial matches, see bobince’s answer below.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)