I am writing Selenium automation scripts in Python. As a process, I need to collect some elements. Below is sample html (I edited to look simple). When I perform a search, I get the search result similar to below.
Now, I need the list of elements in Restaurants and performs some operations. Similarly for Bars, Shopping, Coffee.
The thing is lh and li are at the same node level.
I tried the following xpath but it selects only lh elements
//ul[@id='searchresults']//ancestor::lh
I also gone through helpful Concept XML XLST preceding-sibling and ancestor . But, have not figured out the solution
Sample html code:
<ul id="searchresults">
<lh style="">Restaurants</lh>
<li title="Chamber"><span>Chamber</span></li>
<li title="Chillies"><span>Chillies</span></li>
<li title="Sushi Ville"><span>Sushi Ville</span></li>
<li title="Toasters"><span>Toasters</span></li>
<li title="Joe Grills"><span>Joe Grills</span></li>
<lh style="">Bars</lh>
<li title="Y Cocktails"><span>Y Cocktails</span></li>
<li title="Z Brewery"><span>Z Brewery</span></li>
<li title="X Drinks"><span>X Drinks</span></li>
<lh style="">Shopping</lh>
<li title="Pacific"><span>Pacific</span></li>
<li title="Spencers"><span>Spencers</span></li>
<li title="Hays"><span>Hays</span></li>
<lh style="">Coffee</lh>
<li title="Roasters"><span>Roasters</span></li>
<li title="Coffee Beans"><span>Coffee Beans</span></li>
<li title="Coffee Cafe"><span>Coffee Cafe</span></li>
</ul>
your help is very much appreciated and please let me know any information I am missing or needed which will help to solve this.