Selenium Python; Using xpath, find_element successfully finds the first element, but find_elements returning an empty set, path unchanged

I’m very new to Selenium so sorry if I’ve missed a core step somehow. Here’s my code:

By this point it has navigated to a person’s Twitter profile and wants to collect all the tweet “cards” that have loaded so far.

cards = driver.find_elements_by_xpath('//div[@data-testid="tweet"]')
print(cards)
>>>[]

But strangely,

card = driver.find_element_by_xpath('//div[@data-testid="tweet"]')
print(card.text)

does correctly return all of the text in the very first tweet on the profile.

Answer

print this print(len(driver.find_elements_by_xpath('//div[@data-testid="tweet"]'))) and let us know the size of the list.

Also print(cards) would print hex code of the web elements. not the text on them.

also iterate like this :

cards = driver.find_elements_by_xpath('//div[@data-testid="tweet"]')
for card in cards:
   print(card.text)

or

cards = driver.find_elements_by_xpath('//div[@data-testid="tweet"]')
  for card in cards:
     print(card.get_attribute('innerText'))

Update :

find_elements works on a principle of implciit waits, driver.implicitly_wait(50) put that after you initialize the browser.