【发布时间】:2018-04-21 01:54:56
【问题描述】:
我从表中获取行,例如:
def get_rows_from_table(self) -> List[WebElement]:
table_rows = self.table.find_elements(By.TAG_NAME, "tr")
return table_rows
table_rows是List[WebElement],单行有很多单元格,所以单行本身也应该是一个列表。因此,当我写这样的东西时:
def get_a_specific_row_from_table(self, table_rows, row_num: int) -> List[WebElement]:
return table_rows[row_num - 1]
我收到一个错误:Expected type 'List[WebElement]', got 'WebElement' instead => 这是因为该 List 中的一个元素被定义为 WebElement。
如果我想得到一个单元格,它应该是这样的:
cell = table_row[1]
那么这一行就是一个列表。我的问题是:我们应该如何对待单行表行?作为元素还是元素列表?将所有表行定义为List[List[WebElement]]
【问题讨论】:
标签: python selenium selenium-webdriver html-table