title: Selenium element selection on Instagram
body: <p>I am trying to create an Instagram bot that likes images by selecting the 'heart element' from the webpage and clicking it.</p>
  
  <p>I saw that the element was wrapped like so:</p>
  
  <pre><code>&lt;div class="eo2As "&gt;
  &lt;section class="ltpMr Slqrh"&gt;
  &lt;a class="fr66n tiVCN" href="#" role="button"&gt;
  &lt;span class="Szr5J coreSpriteHeartOpen "&gt;Like&lt;/span&gt;&lt;/a&gt;
  </code></pre>
  
  <p>and the class values are same for all the unliked heart elements for the whole page.</p>
  
  <p>My code:</p>
  
  <pre><code>from selenium import webdriver
  username = "----"
  password = "----" #values present in original file
  
  getdriver = ("https://www.instagram.com/accounts/login/")
  
  driver = webdriver.Chrome(r'C:\testDir\chromedriver_win32\chromedriver.exe')
  driver.get(getdriver)
  
  driver.find_element_by_xpath("//input[@name='username']").send_keys(username)
  driver.find_element_by_xpath("//input[@name='password']").send_keys(password)
  driver.find_element_by_xpath("//button[contains(.,'Log in')]").click()
  
  #working perfectly till here
  
  like = driver.find_element_by_css_selector('.Szr5J.coreSpriteHeartOpen')
  #spits error in this line
  
  for x in range(0,len(like)):
      if like[x].is_displayed():
          like[x].click()
  </code></pre>
  
  <p>It keeps spitting the error:</p>
  
  <pre><code>selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".Szr5J.coreSpriteHeartOpen"}
  </code></pre>
  
  <p>I tried using different patterns of class names but I am unable to figure out how to do this! </p>
  
  <p>Any help will be appreciated!</p>