'Using find_element_by_xpath to extract img alt value coming up empty

I don't receive an error or anything to tell me what's wrong, the list I'm appending the value to is just coming up empty. In my code, getting the values for variables page_cards, ticker, and optCriteria all work. I've tried following, following-sibling, and several other variations with no luck.

try:
    page_cards = driver.find_elements_by_xpath('//article[@data-testid="tweet"]')
except NoSuchElementException:
    continue

for card in page_cards:
    try:
        ticker = card.find_element_by_xpath('//span/a[starts-with(text(),"$")]').text.replace('$', '')
        optCriteria = card.find_element_by_xpath('//span/a[starts-with(text(),"$")]'
                                                 '/../following-sibling::span').text.split('\n')[0].replace('-', '').replace('$', '')
        emoji = card.find_element_by_xpath('//span/a[starts-with(text(),"$")]/..//'
                                           'following-sibling::img[@alt= "Ox" OR @alt= "Bear face"]/@alt')
        tradeCriteria = str(ticker+optCriteria+emoji)
    except NoSuchElementException:
        continue

enter image description here



Solution 1:[1]

from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import Select, WebDriverWait

def wait_element_visible(self, delay, *locator):
    WebDriverWait(driver, delay).until(
    ec.visibility_of_element_located(locator)
    )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manzurul Hoque Rumi