U
U
udi2014-02-24 14:45:33
XPath
udi, 2014-02-24 14:45:33

How to get elements between tags in XPath?

I have, for example, a sequence of tags

<li>1</li>
<li><div><a>2</a></div></li>
<li>3</li>
<li>4</li>
<li>5</li>
<li><div><a>6</a></div></li>
<li>7</li>
<li>8</li>

How can I get only the li's that come between the tags containing the div/a?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2014-02-24
@udi

//li[div/a][1]/
    following-sibling::li[div/a][1]/
        preceding-sibling::li[
            preceding-sibling::li[div/a]
        ]

Are you in the middle of an XPath test?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question