Example: web_reg_find
In Example 1, web_reg_find searches for the text string "Welcome". If the string is not found, it fails and the script execution stops.
In Example 2, based on example 1, shows error handling in the script.
In Example 3, web_reg_find searches for the text string "Error." If the string is found, it fails and the script execution stops.
In Example 4, web_reg_find searches for the text string "ABC". The path of script execution depends on whether the string is found.
In Example 5, an ID argument "XYZ" associates the call to web_reg_find with a line in the log file.

In the following example, web_reg_find searches for the text string "Welcome". If the string is not found, it fails and the script execution stops.
// Run the Web Tours sample
web_url("WebTours",
"URL=http://localhost/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST );
// Set up check for successful login by looking for "Welcome"
web_reg_find("Text=Welcome",
LAST );
// Now log in
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=jojo", ENDITEM,
"Name=password", "Value=bean", ENDITEM,
"Name=login.x", "Value=35", ENDITEM,
"Name=login.y", "Value=14", ENDITEM,
LAST );

Example 2 is the same as example 1, but because Save Count is used, the script execution is not halted on failure. Instead, the error is handled in the code.
// Run the Web Tours sample
web_url("WebTours",
"URL=http://localhost/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST );
// Set up check for successful login by looking for "Welcome"
web_reg_find("Text=Welcome",
"SaveCount=Welcome_Count",
LAST );
// Now log in
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=jojo", ENDITEM,
"Name=password", "Value=bean", ENDITEM,
"Name=login.x", "Value=35", ENDITEM,
"Name=login.y", "Value=14", ENDITEM,
LAST );
// Check result
if (atoi(lr_eval_string("{Welcome_Count}")) > 0){
lr_output_message("Log on successful.");
}
else{
lr_error_message("Log on failed");
return(0);
}

In the following example, web_reg_find searches for the text string "Error." If the string is found, it fails and the script execution stops.
web_reg_find("Text/IC=Error", "Fail=Found", LAST ); web_url("Step", "URL=...", LAST );

In the following example, web_reg_find searches for the text string "ABC". If the string is not found, the script executes Action A. If the string is found one or more times, it executes Action B.
web_reg_find("Text=ABC", "SaveCount=abc_count", LAST ); web_url("Step", "URL=...", LAST ); if (atoi(lr_eval_string("{abc_count}")) == 0) { // ACTION A lr_output_message("Found Ct is zero"); } else { // ACTION B lr_output_message("Found Ct is %s", lr_eval_string("{abc_count}")); }

In the following example, an ID argument "XYZ" associates the call to web_reg_find with a line in the log file. When looking for the entry in the log file that logged the call to web_reg_find, searching for the string "XYZ" will make it much easier.
web_reg_find("Text=mitcham", "ID=XYZ", LAST ); web_url("web_url", "URL=http://lazarus/", "TargetFrame=", "Resource=0", "Referer=", LAST );
The entries in the log file will be one of the following, depending on whether the web_reg_find succeeded in finding the text "mitcham" was found:
Action1.c(12): Matched web_reg_find with "Fail=NotFound" ("XYZ"). Text "mitcham" (count=78)
Action1.c(10): Error: No match for web_reg_find with "Fail=NotFound" ("XYZ"). Text "mitcham"