UI自动化测试-21--WebDriver--操作表格

 

 

from selenium import webdriver
from time import sleep

'''
操作表格:
1、打印某个单元格的元素
2、打印整个表格的元素
'''
driver = webdriver.Chrome()
driver.get('http://sahitest.com/demo/tableTest.htm')
'''
行:
/html/body/table[1]/tbody/tr[1]/td[1]
/html/body/table[1]/tbody/tr[2]/td[1]
/html/body/table[1]/tbody/tr[3]/td[1]
/html/body/table[1]/tbody/tr[3]/td[1]
列:
/html/body/table[1]/tbody/tr[1]/td[1]
/html/body/table[1]/tbody/tr[1]/td[2]

'''
rows = len(driver.find_elements_by_xpath('/html/body/table[1]/tbody/tr'))
print(rows)
cols = len(driver.find_elements_by_xpath('/html/body/table[1]/tbody/tr[1]/td'))
print(cols)

for i in range(1, rows+1):
for j in range(1, cols+1):
ele = driver.find_element_by_xpath('/html/body/table[1]/tbody/tr[{}]/td[{}]'.format(i, j))
print(ele.text)



driver.quit()
上一篇:将Vue页面导出为pdf格式并进行下载


下一篇:API接口测试汇总