title: Why selenium code doesn't work every time?
body: <p><strong>I am currently working on this webpage:</strong></p>
  
  <p><a href="https://www.orbitz.com/Flights-Search?trip=oneway&amp;leg1=from:Hong%20Kong,to:New%20York%20City,departure:01/01/2018TANYT&amp;passengers=children:0,adults:1,seniors:0,infantinlap:Y&amp;mode=search" rel="nofollow noreferrer">https://www.orbitz.com/Flights-Search?trip=oneway&amp;leg1=from:Hong%20Kong,to:New%20York%20City,departure:01/01/2018TANYT&amp;passengers=children:0,adults:1,seniors:0,infantinlap:Y&amp;mode=search</a></p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>#function for searching for all "details" button, return list
  def search_detail_button():
      detail_buttons = browser.find_elements_by_css_selector("span.show-flight-details")
      return (detail_buttons)
  
  ##Open all details pages
  def open_details():
      time.sleep(3)
      for button in search_detail_button():
          button.click()
          time.sleep(1.5)
  
  open_details()
  </code></pre>
  
  <p><strong>Expected result:</strong></p>
  
  <p>All "Flight details and baggage fees" would be opened. </p>
  
  <p><strong>Actual result:</strong></p>
  
  <p>Sometimes it works, sometimes it gives me an exception.
  Why would a code sometimes work, sometimes don't?</p>