'How to create list of rows from a table

I have a table on a webpage.

I want to create a list from rows of the table.

I will then process the list items.

Each table row has an attribute name="entry" so I tried to use that:

for element in wd.find_elements_by_name("entry"):
     row = element.row

This fails because there is no such attribute row.

Question

How can I populate a Python list with the rows from a HTML table?



Solution 1:[1]

Ok, after some searching and trying different options, I finally managed it to work:

def get_contact_list(self):
    wd = self.app.wd
    self.open_home_page()
    contacts = []
    for element in wd.find_elements_by_name("entry"):
        cells = element.find_elements_by_tag_name("td")
        text = cells[1] and cells[2]
        id = element.find_element_by_name("selected[]").get_attribute("value")
        contacts.append(Contact(name=text, id=id))
    return contacts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Witold Do?owicz