'Can not obtain a specific td from td_list through find_element_by_class_name or find_element_by_css_selector

When obtaining a specific td which is existed from td_list, I can not find it through class_name, and for the td, it only has a class_name and a title.

enter image description here

Here is my code:

td_list = self.driver.find_elements_by_xpath(".//tbody/tr/td")
for td in td_list:

print("what we got")
print(td.find_elements_by_css_selector("[class='day.disabled.offday']"))

    if td.find_elements_by_css_selector("[class='day.disabled.offday']") == []:

    self.driver.refresh()
    break

    else:
    click_date = self.driver.find_elements_by_class_name("day.disabled.offday")
    break

and it keeps refreshing and outputting with:

what we got
[]
what we got
[]
...

How should I change it to obtain the specific td( class name ="day disabled offday") Great thanks!



Solution 1:[1]

Did you try the same with this //*[@class='day disabled offday'] XPath ?

td_list = self.driver.find_elements_by_xpath(".//tbody/tr/td")
for td in td_list:

  print("what we got")
  offday_list = td.find_elements_by_xpath(".//*[@class='day disabled offday']")
  print(len(offday_list))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cruisepandey