title: Unable to find img element with xpath
body: <p>Can anyone tell me why the code below won't return an emoji attribute...</p>
  <pre><code>from selenium.webdriver import Chrome
  import time
  from selenium.common.exceptions import NoSuchElementException
  import re    
  
  # open webpage and allow time to load entirely
  driver = Chrome()
  driver.implicitly_wait(15)
  driver.get(&quot;https://twitter.com&quot;)
  time.sleep(2)
  
  # start scraping tweets
  tickerOptDetails = []
  tweet_ids = set()
  tweet_ids.clear()
  print(tweet_ids)
  
  
  def main():
  
      # prevent computer from going to sleep
      pyautogui.press('shift')
  
      print(&quot;--checking for new alert...&quot;)
      page_cards = driver.find_elements_by_xpath('//article[@data-testid=&quot;tweet&quot;]')
  
      for card in page_cards:
          try:
              ticker = card.find_element_by_xpath('//span/a[starts-with(text(),&quot;$&quot;)]').text.replace('$', '')
              optCriteria = card.find_element_by_xpath('//span/a[starts-with(text(),&quot;$&quot;)]'
                                                       '/../following-sibling::span').text.split('\n')[0]\
                  .replace('-', '').replace('$', '')
              emoji = card.find_element_by_xpath(&quot;//img[contains(@src,'https://abs-0.twimg.com/emoji/v2/svg/1f402.svg')&quot;
                                                 &quot; or contains(@src,'https://abs-0.twimg.com/emoji/v2/svg/1f43b.svg')]&quot;)\
                  .get_attribute(&quot;title&quot;)
              
  
              tradeCriteria = str(ticker+optCriteria)
          except NoSuchElementException:
              continue
  
         if tradeCriteria:
              tweet_id = ' '.join(tradeCriteria)
              if tweet_id not in tweet_ids:
                   tweet_ids.add(tweet_id)
                   if 13 &lt; len(tradeCriteria) &lt; 22 and re.search(r'\d{8} \D ', tradeCriteria):
  
                        print(tradeCriteria)
                        print(emoji)
  
  main()
  </code></pre>
  <p>But then the following code will return an emoji attribute...</p>
  <pre><code>from selenium.webdriver import Chrome
  import time
  from selenium.common.exceptions import NoSuchElementException
  import re
  
  
  # open webpage and allow time to load entirely
  driver = Chrome()
  driver.get(&quot;https://twitter.com&quot;)
  time.sleep(2)
  
  # start scraping tweets
  tickerOptDetails = []
  emojiSet = []
  tweet_ids = set()
  last_position = driver.execute_script(&quot;return window.pageYOffset;&quot;)
  scrolling = True
  tweet_ids.clear()
  print(tweet_ids)
  page_cards = driver.find_elements_by_xpath('//article[@data-testid=&quot;tweet&quot;]')
  
  while scrolling:
      page_cards = driver.find_elements_by_xpath('//article[@data-testid=&quot;tweet&quot;]')
      for card in page_cards:
          try:
              ticker = card.find_element_by_xpath('//span/a[starts-with(text(),&quot;$&quot;)]').text.replace('$', '')
              optCriteria = card.find_element_by_xpath('//span/a[starts-with(text(),&quot;$&quot;)]'
                                                       '/../following-sibling::span').text.split('\n')[0].replace('-', '').replace('$', '')
              emoji = card.find_element_by_xpath(&quot;//img[contains(@src,'https://abs-0.twimg.com/emoji/v2/svg/1f402.svg') or&quot;
                                                 &quot; contains(@src,'https://abs-0.twimg.com/emoji/v2/svg/1f43b.svg')]&quot;)\
                  .get_attribute(&quot;title&quot;)
              
              tradeCriteria = str(ticker+optCriteria)
          except NoSuchElementException:
              continue
  
          if tradeCriteria:
              tweet_id = ''.join(tradeCriteria)
              if tweet_id not in tweet_ids:
                  tweet_ids.add(tweet_id)
                  if 13 &lt; len(tradeCriteria) &lt; 22 and re.search(r'\d{8} \D ', tradeCriteria):
  
                      print(tradeCriteria)
                      print(emoji)
  
      scroll_attempt = 0
      while True:
          # check scroll position
          driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')
          time.sleep(2)
          curr_position = driver.execute_script(&quot;return window.pageYOffset;&quot;)
          if last_position == curr_position:
              scroll_attempt += 1
  
              if scroll_attempt &gt;= 3:
                  scrolling = False
                  break
              else:
                  time.sleep(2)
          else:
              last_position = curr_position
              break
  
  print(tweet_ids)
  </code></pre>
  <p>I know I've added the scrolling to the second code, so it's looking at the entire page and returning the elements I'm looking for. But other than that they're more or less the same. I could run the first code every few seconds and it will never find the emoji element. It will find the ticker and optCriteria no problem and print them together as the tradeCriteria, but it will never find the emoji attribute even if it's there.</p>
  <p>I tried both implicitly wait and explicitly wait, but neither one worked. I also tried having the emoji xpath line in the if statement <code>if 13 &lt; len(tradeCriteria) &lt; 22 and re.search(r'\d{8} \D ', tradeCriteria):</code>, but that didn't work either.</p>