Web Table operations 2 (WinRunner, TSL)
Service Functions – Windows Web GUI / WinRunner
Loop through web page in order to find matching table
# Attention! This is the low-level function which is supposed to be called in the loop # Set the proper window public function wb_ht_find_table(in key_cell, in key_row, in key_column, out table_desc, in regex_flag, in exp_location, in loc_start, in loc_end) { # mandatory parameters # in key_cell, in key_row, in key_column # optional parameters # in regex_flag, in find_first, in exp_location, in loc_start, in loc_end auto rc; auto location; if (loc_start == "") loc_start = 0; if (loc_end == "") loc_end = _wb_location_max; if (exp_location == "") exp_location = loc_start; if (exp_location < loc_start) exp_location = loc_start; if (exp_location > loc_end) exp_location = loc_end; # Check expected location rc = wb_ht_tbl_cell_exists(exp_location, key_cell, key_row, key_column, table_desc, regex_flag); if (rc == E_OK) return(E_OK); # Scan loop location = loc_start-1; while (1) { location++; # Search range exceeded, exit if (location > loc_end) return(E_NOT_FOUND); # Search range exceeded, exit if (location > _wb_location_max) return(E_NOT_FOUND); # Search rc = wb_ht_tbl_cell_exists(location, key_cell, key_row, key_column, table_desc, regex_flag); # FAIL exit (no more tables) if (rc == E_NOT_FOUND) return(rc); # FAIL exit (failed reading table) if (rc == E_GENERAL_ERROR) return(rc); # PASS exit (table found) if (rc == E_OK) return(rc); # Table found, cell not exists - continue search if (rc == E_ITEM_NOT_FOUND) continue; # Unknown state - exit break; } return(E_GENERAL_ERROR); }
Load web table data into matrix
# Attention! This is the low-level function. Set the proper window public function wb_ht_load_table(in table, inout mxTable[]) { auto rc, i, j, value, actual_text_length; auto col_count, row_count; # clean up data matrix delete mxTable[]; rc = obj_exists(table); if (rc != E_OK) return(E_GENERAL_ERROR); # Get the boundaries rc = tbl_get_cols_count(table, col_count); if (rc != E_OK) return(E_GENERAL_ERROR); rc = tbl_get_rows_count(table, row_count); if (rc != E_OK) return(E_GENERAL_ERROR); for (i=1;i<=row_count;i++) { for (j=1;j<=col_count;j++) { # Note: this block is the workaround for non-rectangular tables rc = web_obj_get_text(table, "#" & i, "#" & j, value); if (rc != E_OK) { mxTable[i,j] = ""; continue; } # Get text if cell exists rc = web_tbl_get_cell_data(table, "#" & i, "#" & j, 0, value, actual_text_length); if (rc != E_OK) return(E_GENERAL_ERROR); mxTable[i,j] = str_trim(value); } } mxTable[0, "sys", "colCount"] = col_count; mxTable[0, "sys", "rowCount"] = row_count; return(E_OK); }
Load a range of web table data into matrix
public function wb_ht_load_table_range(in table, in start_row, in end_row, inout mxTable[]) { auto rc, i, j, value, actual_text_length; auto col_count, row_count, row_index; # clean up data matrix delete mxTable[]; rc = obj_exists(table); if (rc != E_OK) return(E_GENERAL_ERROR); # Get the boundaries rc = tbl_get_cols_count(table, col_count); if (rc != E_OK) return(E_GENERAL_ERROR); rc = tbl_get_rows_count(table, row_count); if (rc != E_OK) return(E_GENERAL_ERROR); if (start_row > row_count) start_row = row_count; if (end_row < start_row) end_row = start_row; if (end_row > row_count) end_row = row_count; row_index = 0; for (i=start_row;i<=end_row;i++) { row_index++; for (j=1;j<=col_count;j++) { # Note: this block is the workaround for non-rectangular tables rc = web_obj_get_text(table, "#" & i, "#" & j, value); if (rc != E_OK) { mxTable[row_index,j] = ""; continue; } # Get text if cell exists rc = web_tbl_get_cell_data(table, "#" & i, "#" & j, 0, value, actual_text_length); if (rc != E_OK) return(E_GENERAL_ERROR); mxTable[row_index,j] = str_trim(value); } wg_anti_sleep(); } mxTable[0, "sys", "colCount"] = col_count; mxTable[0, "sys", "rowCount"] = row_index; return(E_OK); }