Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98775

How can I scrape the xpath for each link in the ``?

$
0
0

I am trying to write a program that writes code for me. Imagine that I have a <ul> list on a website and I need to scrape all the xpath selectors for each element on that list. Is there an easy way to tell python to grab the xpath selectors for all of the elements in the <ul>?

For example we have this <ul>:

<ul id="test">
    <li><a href="#">Zurich</a></li>
    <li><a href="#">Geneva</a></li>
    <li><a href="#">Winterthur</a></li>
    <li><a href="#">Lausanne</a></li>
    <li><a href="#">Lucerne</a></li>
  </ul>

And I have this code in python:

ul= driver.find_elements_by_id('test')

for element in ul:
    selector = **find the xpath/selector**
    text = element.text  

How can I scrape the xpath for each link in the <ul>?


Viewing all articles
Browse latest Browse all 98775

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>