I am creating a program that uses selenium to extract data from a website. In this case I'm trying to get the length of the lesson. I have the following code on a webpage
<li class="">
<a href="/academy/lesson/intro-to-personality.html" data-virtual="3">
<span class="lesson__title">Intro to Personality</span></a>
<span class="lessonTime">4:16</span>
</li>
<li class="">
<a href="/academy/lesson/intro-to-real-estate.html" data-virtual="3">
<span class="lesson__title">Intro to Real Estate</span></a>
<span class="lessonTime">6:16</span>
</li>
<li class="is-viewing" test-id="course_nav_current_lesson">
<a href="/academy/lesson/freudian-defense-mechanisms.html" data-virtual="3">
Freudian Defense Mechanisms: Definition, Levels & Examples</a>
<span class="lessonTime">7:29</span>
<span class="icon-eye"></span>
</li>
The webpage contains a list of around 8-15 other lessons length's but I'm only interested in the one that the user is assigned. Since it won't visit the same webpage every time the xpath will be dynamic. The only two things that are consistent is the fact that the lesson that the user has been assigned is always at the bottom and the fact that it has a special class called is-viewing. I tried using this code to extract the data:
lessonlength = driver.find_element_by_class_name('lessonTime').get_attribute('innerHTML')
print(f'Lesson is {lessonlength} long')
This returns 4:16 since it's the first element with the same class as the one defined. Is there a way to get the last class found (since it's always at the end).