find_element_by_tag_name(RowOfAtable)返回什么?在Python中

时间:2014-08-28 07:00:50

标签: python html

我正在尝试获取html表第一行的列,这是html代码:

<table id="switches-table" class="display initialized dataTable" cellspacing="0" cellpadding="0" border="0" aria-describedby="switches-table_info">
<thead>
<tr role="row" class="row_selected">
<th class="ui-state-default center" data-column-index="0" role="columnheader" rowspan="1" colspan="1" style="width: 1%;" aria-label="">
<th class="center ui-state-default" data-column-index="1" role="columnheader" tabindex="0" aria-controls="switches-table" rowspan="1" colspan="1" aria-label="Name: activate to sort column ascending">
<th class="center ui-state-default" data-column-index="2" role="columnheader" tabindex="0" aria-controls="switches-table" rowspan="1" colspan="1" aria-label="IP: activate to sort column descending" aria-sort="ascending">
<th class="center ui-state-default" data-column-index="3" role="columnheader" tabindex="0" aria-controls="switches-table" rowspan="1" colspan="1" aria-label="Software Version: activate to sort column ascending">
<th class="center ui-state-default" data-column-index="4" role="columnheader" tabindex="0" aria-controls="switches-table" rowspan="1" colspan="1" aria-label="Health: activate to sort column ascending">
</tr>
</thead>

我想达到属性(aria-label) 我首先得到带有标记的表头,然后用标记行然后第一行的列,它必须返回一个元素数组,这是正确的吗? 所以我试图找到它的长度并循环通过它,然后我的下一步是找到属性,但现在的主要问题是: 当我使用find_element_by_tag_name("th)时,我无法弄清楚它是什么类型或返回什么类型? 到目前为止这是我的代码

   try:
      thead = table.find_element_by_tag_name("thead")
      firstRow = thead.find_element_by_tag_name("tr")
      colOfFirstRow = firstRow.find_element_by_tag_name("th")

      for i in range (0,colOfFirstRow.__len__()-1):  
          wanted = colOfFirstRow.find_elements_by_class_name("center ui-state-default")
          print colOfFirstRow.attribute["aria-lable"].split()[0]

      if th.attribute["aria-lable"].split()[0].__eq__(columnName): //columnName is a paramenter
            flag = 1
            return True
      if flag == 0:
            return False
    except:
        print "fail"

0 个答案:

没有答案