how to know the number of rows of a table in python?



I’m doing tests with selenium and wanted to print the number of rows in the table, but for some reason it’s not working and gives me this error "TypeError: object of type ‘WebElement’ has no len()" how could I do for print the number of lines on the table?

    tabela = self.driver.find_element_by_xpath("/html/body/div[1]/div/table")
    tabela2 = len(tabela)


Instead of

    tabela = self.driver.find_element_by_xpath("/html/body/div[1]/div/table")


    tabela = self.driver.find_elements_by_xpath("/html/body/div[1]/div/table")

If this returns any elements, it will return an array of webelements, and you can iterate through them as you have.

Answered By – C. Peck

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More