Home getting the next element with xpath
Reply: 0

getting the next element with xpath

user2734
1#
user2734 Published in April 22, 2018, 12:52 am

I have the following html block, I'm trying to get all the city links under Alabama in this case. This is the xpath I have constructed

//h3/a[contains(text(),'Alabama')]/following::ul/li/a

But The xpath above matches too many things. Any idea what I am doing wrong?

<div class="geoUnit">

                <h3><a href="http://example.com/" style="background-color: rgba(0, 0, 0, 0);">Alabama</a></h3>
                  <ul style="background-color: rgba(0, 0, 0, 0);">
                    <li style="background-color: rgba(0, 0, 0, 0);"><a href="http://example.com/" style="background-color: rgba(0, 0, 0, 0);">Auburn</a></li>
                    <li><a href="http://example.com/">Birmingham</a></li>
                    <li><a href="http://example.com/">Dothan</a></li>
                    <li><a href="http://example.com/">Gadsden</a></li>
                    <li><a href="http://example.com/">Huntsville</a></li>
                    <li><a href="http://example.com/">Mobile</a></li>
                    <li><a href="http://example.com/">Montgomery</a></li>
                    <li><a href="http://example.com/">Muscle Shoals</a></li>
                    <li><a href="http://example.com/">Tuscaloosa</a></li>
                 </ul>
</div>

I want the following to be selected as an array in this case. I want to extract each city link. I am using xpath inside of Java

                    <li style="background-color: rgba(0, 0, 0, 0);"><a href="http://example.com/" style="background-color: rgba(0, 0, 0, 

0);">Auburn</a></li>
                        <li><a href="http://example.com/">Birmingham</a></li>
                        <li><a href="http://example.com/">Dothan</a></li>
                        <li><a href="http://example.com/">Gadsden</a></li>
                        <li><a href="http://example.com/">Huntsville</a></li>
                        <li><a href="http://example.com/">Mobile</a></li>
                        <li><a href="http://example.com/">Montgomery</a></li>
                        <li><a href="http://example.com/">Muscle Shoals</a></li>
                        <li><a href="http://example.com/">Tuscaloosa</a></li>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301659 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO