-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
  • 183,867
  • 41
  • 278
  • 352
Lihis69
  • 9
  • 1
  • 2
  • 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
  • 183,867
  • 41
  • 278
  • 352