I am using python + selenium to automate common behavior through a website. I have now arrived at a point where there is a div <div class="teetime-grid" data-baan="1">
with a number of <div class="btn btn-success teetime has-bookings>
inside <a href>
tags. Please find a snippet of the HTML page below to clarify.
<div class="teetime-grid" data-baan="1">
<a href="#">
<div class="btn btn-success teetime has-bookings " data-time="1645165200"
title="Er zijn nog 3 beschikbare plaatsen op deze starttijd">
<span class="time">07:20</span>
<div class="icons">
<span class="icon bezet geslacht-m"> </span>
<span class="icon vrij"> </span>
<span class="icon vrij"> </span>
<span class="icon vrij"> </span>
</div>
</div>
</a>
<a href="#">
<div class="btn btn-success teetime has-bookings " data-time="1645165800"
title="Er zijn nog 1 beschikbare plaatsen op deze starttijd">
<span class="time">07:30</span>
<div class="icons">
<span class="icon bezet geslacht-m"> </span>
<span class="icon bezet geslacht-m"> </span>
<span class="icon bezet geslacht-m"> </span>
<span class="icon vrij"> </span>
</div>
</div>
</a>
</div>
I need to access specific <div class="btn btn-success teetime has-bookings>
inside the grid. In Selenium, I know I can do this by using:
driver = webdriver.Chrome()
driver.find_element_by_xpath("//a[2]/div")
To select the second tag in my above example, which in this case has a corresponding time of 07:30 associated with it (it's defined in the <span class="time">07:30</span>
).
Is there also a way to access these elements by the contents of the <span class="time">
instead of specifying the number in the list of <a href>
tags? Because now I still have to know which a[?]
number corresponds to a certain time. If I have to look this up manually every time time there is no point in automating this browser action to begin with.