XPath – Select first element after some other element

I had to read through your question a couple of times but I think I understand it. What you are interested in is predicates. Predicates allow you to pick nodes based on conditions.

For example, you could do:

//a[text()='second dropdown menu']/following::ul[1]/li/a[text()='link i want to find']

this would select any anchor with certain text in, find the next ul, then proceed through it’s children.

Also, you can specify positional index within a result set, the following XPath is a demonstration (but it won’t solve your problem):

//a[text()='first dropdown menu']/ul/li[last()]/a/text()

or you could use axes to navigate across siblings/ancestors/children:

//a[ancestor::ul/preceding::a[1]/text() = 'second dropdown menu']/text()

So I’m not sure I quite understood your question but this should help you write your XPath.

Basically, I’m assuming your XPath matches the anchor in multiple lists and you want to make sure you pick the right one. At some point in your XPath you need a predicate to specify a condition that will only be true for the list your desired node is in.

Leave a Comment

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