In the absence of more HTML and/or the URL I hope the following is helpful from a possible logic point of view. I selected a website with a table that has a price column (This is a substitute for datetime) and a column with text to match on. Hopefully my attempt won't be judged too harshly.
I outline the steps that I think are similar to your problem i.e.
- Use xpath to select two lists where one list is
a tag elements matched by text and the other is the preceding::td[1] . In your example I think possible xpaths are:
//a[text()="Job Created"]/preceding::td
//a[text()="Job Created"]
You take the text from the first list and treat as required. You would need a function to format your datetimes ready for sorting. The second list is kept as elements so can later be clicked on. This assumes that your datetimes can be treated and sorted in an acceptable fashion.
Combine these in a single list of tuples and then sort on the first in each tuple
So, an outline with my admittedly not perfect case study:
from selenium import webdriver
from operator import itemgetter
url ="https://www.wiseowl.co.uk/dax/london/"
driver = webdriver.Chrome()
driver.get(url)
#used title myDates although in my example I am using prices
myDates =[int(element.text.strip('£')) for element in driver.find_elements_by_xpath("//a[text() = 'Book places']/preceding::td[1]")]
myData = [element for element in driver.find_elements_by_xpath("//a[text() = 'Book places']")] #links in adjacent column
combined = list(zip(myDates,myData))
combined = sorted(combined,key=itemgetter(0), reverse=True) #sort list on first 'column'
combined[0][1].click() #click first in descending list
#other code
# driver.quit()
HH:MM:SSrelated element you need to interact/click?