Home getting the next element with xpath

# getting the next element with xpath

Arya
1#
Arya Published in 2017-12-08 00:38:43Z
 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?   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 
• Auburn
• Birmingham
• Dothan
• Huntsville
• Mobile
• Montgomery
• Muscle Shoals
• Tuscaloosa
• 
kjhughes
2#
 I'm trying to get all the city links under Alabama in this case. Your XPath does select all a that follow the targeted heading. But The xpath above matches too many things. Perhaps there are additional ul elements following the targeted heading in your complete document. In this case, you can append a [1] to the ul step in your XPath to limit the selection to the immediately following ul element: //h3/a[contains(text(),'Alabama')]/following::ul[1]/li/a  or, cleaned-up a bit: //h3[a='Alabama']/following-sibling::ul[1]/li/a  This will limit the a elements to those of just the immediately following ul.
 You need to login account before you can post.
Processed in 0.372466 second(s) , Gzip On .