See the question and my original answer on StackOverflow

All your XPATH expressions start with '//' which means "start from root of the document and search recursively". So when you do this:


You will start not from link, but from the document's root. You probably want to do this instead:


which is equivalent to


'.' means the current node. '/' means search only the direct children, not recursively.