title: How to loop multiple elements in python selenium (different CSS selectors)
body: <p>I am trying to loop inside a class <code>offer-list-wrapper</code> which has multiple elements inside, almost all the elements are common in the web page for search A and search B (I am scraping a crawler).</p>
  
  <p>As you can see in both images, <code>offer-list-wrapper</code> is a common element.</p>
  
  <p>I want to extract the data that is inside every <code>organic-offer-wrapper organic-gallery-offer-inner</code> and <code>organic-list-offer-inner m-gallery-product-item-v2</code>  classes. Which is very easy to do if you loop inside them with a CSS selector like this:</p>
  
  <pre><code>for element in driver.find_elements_by_css_selector('.organic-list-offer-inner.m-gallery-product-item-v2'):
  </code></pre>
  
  <p>In that way you can get every element inside them.</p>
  
  <p><a href="https://i.stack.imgur.com/i6S57.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i6S57.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/LEurL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LEurL.png" alt="enter image description here"></a></p>
  
  <p>BUT the issue starts here: I need to loop inside both cases with ONE generic code that loop inside both classes, and in case a new class appears it has to loop inside it.</p>
  
  <p>Let me show you my code:</p>
  
  <pre><code>for element in driver.find_elements_by_class_name('offer-list-wrapper'):
      try:
          item_name = element.find_element_by_class_name('organic-gallery-title__content').text
      except:
          item_name = np.nan
      try:
          price = element.find_element_by_class_name('gallery-offer-price').get_attribute('title').replace('$', '').replace(',', '')
          min_order = element.find_element_by_class_name('gallery-offer-minorder').find_element_by_tag_name('span').text.replace(' Pieces', '').replace(' Piece', '').replace(' Units', '').replace(' Unit', '').replace(' Sets', '').replace(' Set', '').replace(' Pairs', '').replace(' Pair', '').replace('Boxes', '').replace('Box', '').replace('Bags', '').replace('Bag', '')     
          # separate min and max price
      except:
          price = np.nan
          min_order = np.nan
  </code></pre>
  
  <p>This first one returns only the first element:</p>
  
  <pre><code>for element in driver.find_elements_by_css_selector('.organic-offer-wrapper.organic-gallery-offer-inner'):
      try:
          item_name = element.find_element_by_class_name('organic-gallery-title__content').text
      except:
          item_name = np.nan
      try:
          price = element.find_element_by_class_name('gallery-offer-price').get_attribute('title').replace('$', '').replace(',', '')
          min_order = element.find_element_by_class_name('gallery-offer-minorder').find_element_by_tag_name('span').text.replace(' Pieces', '').replace(' Piece', '').replace(' Units', '').replace(' Unit', '').replace(' Sets', '').replace(' Set', '').replace(' Pairs', '').replace(' Pair', '').replace('Boxes', '').replace('Box', '').replace('Bags', '').replace('Bag', '')     
          # separate min and max price
      except:
          price = np.nan
          min_order = np.nan
  </code></pre>
  
  <p>This second one only loops inside <code>.organic-offer-wrapper.organic-gallery-offer-inner</code> (returning all elements that I need), but it doesn't loop inside <code>.organic-list-offer-inner.m-gallery-product-item-v2</code></p>