JS脚本分享-读取页面表单
robot中这样引用:${headers} Execute Javascript ${CURDIR}/../../../../05.Files/05.Scripts/head_data_RW.js ARGUMENTS a一、读取页面表单标题
var array_head_row = [];
var array_head = [];
var start = 0;
var end = 0;
var page = arguments;
if (page.search("a")!= -1){
var head_loc = "div thead tr th"#此处必须用css路径
start = 3;/*第三列开始*/
end = -1;/*最后一列没有数据*/
}
else if(page.search("b")!= -1){
var head_loc = "..."
}
array_head_row = document.querySelectorAll(head_loc);
len=array_head_row.length+end;
for (var i=start;i<len;i++){
var text = array_head_row.textContent;
console.log(text);
array_head.push(text);
}
return array_head;
二、获取页面表单body数据
var array_row=[];
var array_column=[];
var array_data_all=[];
var LEN = 15;
var page = arguments;
switch(page)
{
case 'a':
var data_loc = "div tbody tr"
var column_start = 3;/*第三列开始*/
var column_end = -1;/*最后一列没有数据*/
break;
case 'b':
var data_loc = "div tbody tr"
var column_start = 3;
var column_end = -1;
break;
case 'c':
var data_loc = "div tbody tr"
var column_start = 0;
var column_end = 0;
break;
}
array_row = document.querySelectorAll(data_loc);
array_column = array_row.children;
column_end = array_column.length+column_end
for (var i=0,len=array_row.length;i<len;i++){
array_column=array_row.children;
var array_data=[];
for (var j=column_start;j<=column_end;j++){
text = array_column.textContent;
text = text.replaceAll("\n","");#把换行符取代哦
text = text.replaceAll(/(^\s*)|(\s*$)/g,"");#把首尾的空格去掉
if(text.indexOf("}")!=-1){
text_len = text.length;
text = text.substring(text_len-LEN,text_len);
}
console.log(text);
array_data.push(text);
}
array_data_all.push(array_data);
}
return array_data_all;
页:
[1]