title: Locating image src and alt in a specific class with Selenium Python
body: <p>I am trying to find image <code>alt</code> and <code>src</code> on a webpage. But, I am only interested in the image <code>alt</code> and <code>src</code> in a certain <code>class</code>. I don't want to locate images in other classes.</p>
  
  <p>Here is the <code>html</code>:</p>
  
  <pre><code>&lt;div class="the class I want"&gt;
      &lt;img alt="this is the alt I need" src="https://somesite.com/images/image.jpg" width="200" height="200"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Below is a Selenium code that works to locate <strong>all</strong> the images on the page; but, as I mentioned, I only need the images in one particular class.</p>
  
  <pre><code>driver = webdriver.Firefox()
  driver.get('https://www.somesite.com/somepage')
  image_elements = driver.find_elements_by_xpath("//img")
  
  for image in image_elements:
      img_src = image.get_attribute("src")
      alt = image.get_attribute("alt")
  </code></pre>
  
  <p>I am trying to locate the images in the <code>class="the class I want"</code> only.</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>image_elements = driver.find_elements_by_xpath("//div[contains(@class, 'the class I want')]")
  </code></pre>
  
  <p><em>and...</em></p>
  
  <pre><code>image_elements = driver.find_elements_by_css_selector("div.the.class.I.want")
  </code></pre>
  
  <p><em>Also, please note that the class name contains spaces, as indicated above.</em> </p>