迭代使用硒获得的webelement

时间:2014-01-11 03:11:26

标签: python selenium

rows = driver.find_element_by_xpath("//div[@style='display: block;']//table[@style='display: table;']//tr")

当我尝试迭代行时,它会抛出错误TypeError: 'WebElement' object is not iterable

def get_size(e):

   for  entry in e:

     count = count + 1
   return count

get_size(rows)

1 个答案:

答案 0 :(得分:15)

试试这个。这应该工作。使用find_elements_by_xpath

Listlinker = []
Listlinker = driver.find_elements_by_xpath(""//div[@style='display: block;']//table[@style='display: table;']//tr")
for link in Listlinker:
// more code