*** Keywords ***
get cells text
    [Arguments]    ${rowIndex}    ${cells}
    ${row_list}=    Create List
    FOR    ${cellindex}    IN RANGE    1    ${cells}
        ${curText}=    Get Text    //tbody/tr[${rowIndex}]/td[${cellindex}]/span
        append to list    ${row_list}    ${curText}
    END
    [Return]    ${row_list}

get table list  # 返回列表[[],[],[],....]
    [Arguments]    ${WEB_ROW}    ${WEB_CELL}
    ${rows}=    Get Element Count    ${WEB_ROW}    # 获取总行数
    ${cells}=    Get Element Count    ${WEB_CELL}    # 获取总列数
    ${table_list}=    Create list
    FOR    ${rowIndex}    IN RANGE    1    ${rows+1}
        ${row_list}    Get cells text    ${rowIndex}    ${cells}+1
        append to list    ${table_list}    ${row_list}
    END
    [Return]    ${table_list}

  

TEST

FunTable
    open Browser    rule.html    gc
    @{list}=    get table list    //*[@id="table1"]/tbody/tr    //*[@id="table1"]/tbody/tr[1]/td
    ${len}=    Get length    ${list}
    FOR    ${i}    IN RANGE    ${len}
        ${litem}=    Get From List    ${list}    ${i}
        ${len1}=    Get length    ${litem}
        #FOR    ${j}    IN RANGE    ${len1}
        #    ${item}=    Get From List    ${litem}    ${j}
        #    log    ${item}
    #END
        log    ${litem}
    END
    close window

rule.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>表格</title>
	</head>
	<body>
		<table id="table1">
			<thead>
				<tr>
					<td>标题一</td>
					<td>标题2</td>
					<td>标题3</td>
					<td>标题4</td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>1</td>
					<td>2</td>
					<td>6</td>
					<td>6</td>
				</tr>
				<tr>
					<td>1</td>
					<td>2</td>
					<td>6</td>
					<td>6</td>
				</tr>
				<tr>
					<td>3</td>
					<td>4</td>
					<td>6</td>
					<td>6</td>
				</tr>
				<tr>
					<td>5</td>
					<td>6</td>
					<td>6</td>
					<td>6</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>

 

posted on 2021-09-16 15:24  Old-Kang  阅读(123)  评论(0编辑  收藏  举报