U
U
udi2014-02-24 14:07:59
XPath
udi, 2014-02-24 14:07:59

How to get elements before a tag in XPath?

I have, for example, a sequence of tags

<li>1</li>
<li>2</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 lis that come before the tag containing the div/a?
Thank you.

Answer the question

In order to leave comments, you need to log in

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

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

P
PaulZi, 2014-02-24
@PaulZi

(//li/div/a)[1]/../../preceding-sibling::li

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question