Share this page

# Example: web.reg_find

In Example 1, reg_find searches for the text string "Welcome". If the string is not found, it fails and the script execution stops.

In Example 2, reg_find searches for the text string "Error." If the string is found, it fails and the script execution stops.

In Example 3, reg_find searches for the text string "ABC". The execution path of the script changes depending on whether the string is found.

Example 1

In this example, web.reg_find checks for the login name. Commented out, is an alternative example of how to use the function to look for leading and trailing strings.

    {
        // Run the Web Tours sample program
        web.url("WebTours",
            "URL=http://localhost/WebTours/",
            new String[]{
                "Resource=0",
                "RecContentType=text/html",
                "Referer=",
                "Mode=HTML",
                web.LAST
            });

/* In a real script, you will probably use parameterization
for LoginName. For this example, we simply create one parameter.
*/

            lr.save_string("jojo" , "LoginName" );

        // Set up check for successful login by looking for the login name

        web.reg_find("Text=<LoginName>",
            new String[]{
                "SaveCount=WelcomeCount",
                web.LAST
            });

    /*      ******** Alternative ************
    An alternative check which does not require knowing the login name, is to look for the strings that precede and follow the login name when the login is successful.

        web.reg_find("Text=",
            new String[]{
                "TextPfx=Welcome,",
                "TextSfx=, to Web Tours",
                "SaveCount=WelcomeCount",
                web.LAST
            });

    *************************************/

    // Now log in
        web.submit_form("login.pl",
            new String[]{},
            new String[]{
                "Name=username", "Value=<LoginName>", web.ENDITEM,
                "Name=password", "Value=bean", web.ENDITEM,
                "Name=login.x", "Value=35", web.ENDITEM,
                "Name=login.y", "Value=14", web.ENDITEM,
                web.LAST
            });

        /* Check the Welcome Count and take whatever actions are
            appropriate for your script */

        if (lr.eval_int("<WelcomeCount>") == 0 )
            lr.message("Login " + lr.eval_string("<LoginName>") + " unsuccessful");
        else
            lr.message("Login " + lr.eval_string("<LoginName>") + " successful");
    }
    catch (Exception e){}

Example 2

In the following example, 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=Welcome",
        new String []{Fail=Found", "LAST"});
    web.url("test1.html",
        "URL=http://localhost/test1.html",
         new String []{"LAST"});

Example 3

In the following example, 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/IC=ABC",
        new String []{"SaveCount=abc_count", "LAST"});

    web.url("test1.html",
        "URL=http://localhost/test1.html",
         new String []{"LAST"});

    lr.message("Value of abc_count is " + lr.eval_string("<abc_count>"));

    if (lr.eval_int("<abc_count>") == 0)
          lr.message("Not Found");
    else
          lr.message("Found");

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: