Search code examples
python-3.xseleniumselenium-webdriverselenium-chromedrivertags

Not able to get <abbr> tag text / timing selenium


Here is the screenshot of text i want to fetch

full link to inspect element : -

https://m.facebook.com/story.php?story_fbid=4271200939570739&id=344128252278047

I want to fetch the 9 May at 11:21 from the tag please attached screenshot.

Here is the code I tried:

sstry_ctr = driver.find_element_by_xpath(".//*[@class='story_body_container']")
pptime = sstry_ctr.find_element_by_xpath(
    "./header//*[@class='_4g34 _5i2i _52we']//*[@class='_52jc _5qc4 _78cz _24u0 _36xo']/a")
ppptime = pptime.get_attribute('abbr')
print("pptime", pptime)

Output i am getting is "None". please advise


Solution

  • This can be achieved by CSS_SELECTOR or as a matter of fact with different locators also.

    CSS_SELECTOR that we need to use :

    div[data-store-id] h3+div abbr
    

    How to use in code :

    driver.maximize_window()
    wait = WebDriverWait(driver, 30)
    
    driver.get("https://m.facebook.com/story.php?story_fbid=4271200939570739&id=344128252278047")
    post_date = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div[data-store-id] h3+div abbr"))).text
    print(post_date)