In this recipe, we will see how to create a class that can be used to execute a search on Google.
From the File menu, navigate to New | Test, and name the new test SimpleSearch
. Then, create a new function library by navigating to New | Function Library, or use the Alt + Shift + N shortcut. Name the new function library cls.Google.vbs
and associate it with your test.
Proceed with the following steps:
Define an environment variable as
OPEN_URL
.Insert the following code in the new library:
Class GoogleSearch Public Function DoSearch(ByVal sQuery) With me.Page_ .WebEdit("name:=q").Set sQuery .WebButton("html id:=gbqfba").Click End With me.Browser_.Sync If me.Results.WaitProperty("visible", 1, 10000) Then DoSearch = GetNumResults() Else DoSearch = 0 Reporter.ReportEvent micFail, TypeName(Me), "Search did not retrieve results until timeout" End If End Function Public...