Selenium: Iterating through groups of elements Selenium: Iterating through groups of elements selenium selenium

Selenium: Iterating through groups of elements


Use find_elements_by_class_name() to get all blocks and find_element_by_xpath() to get title and company for each person:

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})