How do I get part of website
I would be interested in the number shown in the picture, that is not directly displayed on the page.
How do I get part of website
I would be interested in the number shown in the picture, that is not directly displayed on the page.
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