Loop through HTML with Selenium

Viewed 60

How can I iterate throuah all the list-items of <ol class="daily-weather-list__intervals"?

enter image description here

I want to go though everey sub-item, that is

<li class="daily-weather-list-item" id="DayliWatherListItem0"
<li class="daily-weather-list-item" id="DayliWatherListItem1"
...
<li class="daily-weather-list-item" id="DayliWatherListItem8"

and collect the data stored in the classes

'temperature min-max-temperature__max temperature--warm')
'temperature min-max-temperature__min temperature--warm')

as shown below:

enter image description here

Is there a way to do this using Selenium Webdriver?

2 Answers

use find_elements instead :

for li_values in driver.find_elements(By.CSS_SELECTOR, "ol.daily-weather-list__intervals li"):
    print(li_values.get_attribute('innerHTML'))

See if this works:

weatherList = driver.find_elements_by_xpath(".//div[@class='daily-weather-list-item']")
for e in weatherList:
    minMaxTemp = driver.find_element_by_xpath(".//span[@class='min-max-temperature']/span").text
    warmTemp = driver.find_element_by_xpath(".//span[contains(@class,'temperature__separator')]/span").text
Related