I have the following sample HTML:
<div class="person">
<div class="title">
<a href="http://www.url.com/name/">John Smith</a>
</div>
<div class="company">
<a href="http://www.url.com/company/">SalesForce</a>
</div>
</div>
<div class="person">
<div class="title">
<a href="http://www.url.com/name/">Phil Collins</a>
</div>
<div class="company">
<a href="http://www.url.com/company/">TaskForce</a>
</div>
</div>
<div class="person">
<div class="title">
<a href="http://www.url.com/name/">Tracy Beaker</a>
</div>
<div class="company">
<a href="http://www.url.com/company/">Accounting</a>
</div>
</div>
I am trying to iterate through the list to try and get the following results:
John Smith, SalesForce
Phil Collins, TaskForce
Trace Beaker, Accounting
I am using the following code:
persons = []
for person in driver.find_elements_by_class_name('person'):
title = person.find_element_by_xpath('.//div[@class="title"]/a').text
company = person.find_element_by_xpath('.//div[@class="company"]/a').text
persons.append({'title': title, 'company': company})
However, the above code only iterates through the first person and not through all the people. Any help is appreciated.