-1

How do I get part of website

enter image description here

I would be interested in the number shown in the picture, that is not directly displayed on the page.

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
Lihis69
  • 9
  • 1
  • 2
  • Welcome to Stack Overflow! See: [How do I do X?](https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x) The expectation on SO is that the user asking a question not only does research to answer their own question but also shares that research, code attempts, and results. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – JeffC Feb 08 '21 at 21:06
  • Welcome to Stack Overflow! Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Feb 08 '21 at 21:06

1 Answers1

0

To print the value of the data-datetime attribute you can use either of the following Locator Strategies:

  • Using Python and CSS_SELECTOR:

    print(driver.find_element(By.CSS_SELECTOR, "div.TimeStamp span[data-interval='60']").get_attribute("data-datetime"))
    
  • Using Java and xpath:

    System.out.println(wd.findElement(By.xpath("//div[@class='TimeStamp' and @data-interval='60']")).getAttribute("data-datetime"));
    

Ideally you need to induce WebDriverWait for the visibilityOfElementLocated() / visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using Java and cssSelector:

    System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.TimeStamp span[data-interval='60']"))).get_attribute("data-datetime"));
    
  • Using Python and XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='TimeStamp' and @data-interval='60']"))).get_attribute("data-datetime"))
    
  • 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
  • 151,581
  • 34
  • 225
  • 281