title: Selenium: Iterating through groups of elements
body: <p>I've done this with BeautifulSoup but it's a bit cumbersome, and I'm trying to figure out if I can do it directly with Selenium.</p>
  
  <p>Let's say I have the following HTML, which repeats multiple times in the page source with identical elements but different contents:</p>
  
  <pre><code>&lt;div class="person"&gt;
      &lt;div class="title"&gt;
          &lt;a href="http://www.url.com/johnsmith/"&gt;John Smith&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="company"&gt;
          &lt;a href="http://www.url.com/company/"&gt;SalesForce&lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I need to build a dictionary where the entry for each person looks like:</p>
  
  <pre><code>dict = {'name' : 'John Smith', 'company' : 'SalesForce'}
  </code></pre>
  
  <p>I can easily get Selenium to produce a list of the contents of each top level element by doing:</p>
  
  <pre><code>driver.find_elements_by_class_name('person')
  </code></pre>
  
  <p>But then I can't iterate through the list because the above method doesn't narrow the scope/source to just the contents of that element.</p>
  
  <p>If I try to do something like this:</p>
  
  <pre><code>people = driver.find_elements_by_class_name('person')
  for person in people:
      print person.find_element_by_xpath['//div[@class="title"]//a').text
  </code></pre>
  
  <p>I just get the same name over and over again.</p>
  
  <p>I need to do this group by group because in my case, iterating through the whole page and appending each tag individually won't work (there's infinite scrolling, so it would be really inefficient).</p>
  
  <p>Does anyone know whether it's possible to do this directly in Selenium, and if so how?</p>