Your e-Business Quality Partner eValid™ -- The Web Quality Suite
Browser-Based Client-Side Functional Testing and Validation Page Timing/Tuning Transaction Monitoring. WebSite Spidering & Analysis and Realistic Server Loading.

eValid -- eValid Programmatic Interface (EPI) -- Example Program #03
eValid Home

Example Program #03
This example involves a much more sophisticated process, aimed at automatically determining the relative result page location of a successful search engine invocation. This is the kind of calculation that is commonly done in Search Engine Optimization (SEO) work.

Problem Description
The Google search for KEYWORD yields a set of pages, and you go to the next page by clicking on MORE. On each page, search for KEYWORD and then, finding that, confirm the URL is below it on the page, or does not appear.

# $KEYWORD = the phrase (string) being searched for
# $COMPANY_URL = the company URL that is supposed to be found 
# $COMPANY_DOMAIN = the company DOMAIN that is supposed to be found

InitLink www.google.com

Type the $KEYWORD into the search box

Run the search

page = 1
While (there are still result pages to examine)
	found-index = 0
	found-index = Search the page for an instance of
		$COMPANY_URL or $COMPANY_DOMAIN, if any
	if (found-index > 0)
		OK, there is an instance!

		Report the found-index (page position)
		to the user along with the page number
		where it was found.

		EXIT	
	else
		page = page + 1
	endif
endwhile

Resources

  1. You can compile this program locally from the CPP source: example03.cpp.

  2. Here is the compiled CPP program that you can run locally: example03.exe.
    This demonstrates going to www.google.com and input search for "e2s", from the results (cycling through NEXT until...), stop after confirming that "Nikon" is a match. Manually CLOSE eValid when done, exit not programmed in.

Example Program
This is what a the C++ program that uses the eValid EPI to accomplish the above process looks like.

#include "epi.h"

using namespace std;

int main()
{
    long index;
    ::CoInitialize(NULL);

    IEvalid * pEvalid = NULL;
    HRESULT hr = CoCreateInstance(CLSID_Evalid, NULL,
        CLSCTX_INPROC_SERVER, IID_IEvalid, 
	(void**)&pEvalid);

    if (SUCCEEDED(hr))
// -----------------------------------------------------------------------------
// End of setup section, beginning of programmatic area...
    {
        pEvalid->InitLink(CComBSTR("http://www.google.com/"));
        pEvalid->InputValue(0, 62, CComBSTR("TEXT"), NULL, 
	    CComBSTR("q"), CComBSTR("e2s"), NULL, NULL);
        pEvalid->SubmitClick(0, 64, NULL, CComBSTR("btnG"), 
	    CComBSTR("Google Search"), NULL);
        CComBSTR bstr_Status;
        BOOL bDone = FALSE;

        do {
            pEvalid->MatchString(0, CComBSTR("www.bushmaster.com"), 
		1, NULL);
            pEvalid->get_LastPlaybackStatus(&bstr_Status);
            if (bstr_Status == "ERROR")
            {
                // Click on the Next button
                pEvalid->IndexSet(0);
                pEvalid->IndexFindElement(0, CComBSTR("DOWN"), 
		    CComBSTR("id"), CComBSTR("nn"), NULL, &index);
                pEvalid->IndexFollowLink(0, NULL);
            }
            else
                bDone = TRUE;
        }
        while (!bDone );

        pEvalid->Release();
    }
// -----------------------------------------------------------------------------
    else
    if (hr == E_ACCESSDENIED)
        cout << "Missing a valid EPI license key!" << endl;
    else
        cout << "Unable to load EPI!" << endl;

    ::CoUninitialize();
    return 0;
}