1

My diction is going to be wrong, so forgive the misnomers. I'm looking for the text of the "content" within the span class:

<span class="rating-label" content="5">

I'm looking for "5"

I've tried

driver.find_element_by_class_name('rating-label').text

But I do not receive the "5" back anywhere in that text.

I've also tried

driver.find_elements_by_class_name('rating-label').get_attribute("outerHTML")
driver.find_elements_by_class_name('rating-label').get_attribute("innerHTML")

I've checked the other questions about this, but if I missed one feel free to show me.

Thanks

Guy
  • 46,488
  • 10
  • 44
  • 88
user2723494
  • 1,168
  • 2
  • 15
  • 26

1 Answers1

1

The content attribute is having the value 5. So to extract the value you have to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.rating-label"))).get_attribute("content"))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='rating-label']"))).get_attribute("content"))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352