Selecting Next Link Using XPath

I need to write an XPath expression to get the href attribute of the anchor tag in the html below, which appears immediately after the one marked as "current page" (in the example # notimportant / 2).

<dd>
    <a href="#notimportant/1" class="current-page">1</a>
    <a href="#notimportant/2">2</a>
    <a href="#notimportant/3">3</a>
    <a href="#notimportant/4">4</a>
    <!-- EDIT: Do not return the next sibling if @href ends with /last -->
    <a href="#notimportant/last">last</a>
</dd>

I thought about starting with something like // a [@ class = 'current-page'] /../ next-sibling-of-first-node / @ href, but I'm stuck here ...

Can anyone help me with this? I googled around, but XPath is not my favorite skill (and no, I cannot use jQuery, this is not webapp).

+3
source share
1 answer
//a[@class='current-page']/following-sibling::a[1]
+8
source

Source: https://habr.com/ru/post/1731357/


All Articles