title: Cant find element in xpath (Instagram, selenium, python)
body: <p>Ok ive been trying to make a instagram bot that sends back the src link for a post but im having trouble, i keep getting the error &quot;<em>selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div[4]/div[2]/div/article/div[2]/div/div/div[1]/img</em>&quot; when im trying to get the xpath for the element with the src in it. can anyone help?
  Link: <a href="https://www.instagram.com/direct/inbox/" rel="nofollow noreferrer">https://www.instagram.com/direct/inbox/</a> .</p>
  <pre><code>    def dm_check(self, driver):
          print(&quot;dm_check starts here&quot;)
  
          try:
              self.driver.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[1]/div[2]/div/div/div/div/div[1]/a/div').click()
          except:
              self.driver.get('https://www.instagram.com/direct/inbox/')
              print(&quot;Refreshing...&quot;)
              time.sleep(10)
              self.dm_check(self.driver)
  
  
          print(&quot;dm_check stops here&quot;)
  
          self.download(self.driver)
      
      def download(self, driver):
          print(&quot;download starts here&quot;)
  
          self.driver.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div/div[2]/div[2]/div/div/div/div/div/div/div[2]/img').click()
          post = self.driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[2]/div/div/div[1]/img').get_attribute(&quot;src&quot;)
          print(str(post))
  
          print(&quot;download ends here&quot;)
  
          self.dmessage(self.driver)
  </code></pre>