美文网首页
Python表格定位+XPath定位

Python表格定位+XPath定位

作者: 約見 | 来源:发表于2018-06-23 11:50 被阅读0次

#遍历整个表格

table = driver.find_element_by_id("table")    #获取整个表格对象

trList = table.find_elements_tag_name("tr")  #获取表格中所有行对象

assert len(trList) ==5, u"表格行数不符"

for row in trList:

      tdList = row.find_elements_by_tag_name("td")  #遍历行获取每一行对应的列对象

      for col in tdList:

            print(col.text + "\t"),    #遍历所有列,并打印单元格内容

Python表格定位+XPath定位

#定位表格中某个元素

XPath表达式: //*[id = "table"]/tbody/tr[2]/td[2]    #第二行第二列,tbody是对于表格的标签

#定位表格中的子元素

XPath表达式://td[contains(.,"化妆")]/input[1]

Python表格定位+XPath定位

XPath轴关键字定位

Python表格定位+XPath定位 Python表格定位+XPath定位

相关文章

网友评论

      本文标题:Python表格定位+XPath定位

      本文链接:https://www.haomeiwen.com/subject/wmuryftx.html