如何知道python中table的行数?

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

我正在用 selenium 进行测试,想打印 table 中的行数,但由于某种原因它不起作用,并给我这个错误“TypeError:对象类型 'WebElement' 没有 len()" 我怎么能打印 table 上的行数?

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

而不是

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

如果此 return 有任何元素,它将 return 一个网络元素数组,您可以按原样遍历它们。