could someone please help how to extract all aria-label texts containing "Not available. date" in the below example: aria-label="Not available. 4 June 2020"
> <td role="button"
> aria-disabled="true" aria-label="Not available. 4 June 2020"
> tabindex="-1" style="width: 39px; height: 38px;">2</td>
I tried something like this
driver.find_elements_by_class_name('CalendarDay CalendarDay_1 CalendarDay__defaultCursor CalendarDay__defaultCursor_2 CalendarDay__default CalendarDay__default_3 CalendarDay__highlighted_calendar CalendarDay__highlighted_calendar_4 CalendarDay__blocked_calendar CalendarDay__blocked_calendar_5 CalendarDay__blocked_out_of_range CalendarDay__blocked_out_of_range_6').get_attribute('aria-label')
but doesn't work.
CodePudding user response:
This is by far not the best solution, i would try finding something more specific. But based on the data you have given, this should work too.
from selenium.webdriver.common.by import By
labels = driver.find_elements(By.XPATH, "//td[contains(text(), 'Not available.')]")
texts = [l.get_attribute("aria-label") for l in labels]
