How to get the count of the Google search Result of a page using DP?


Using Descriptive programming (DP) to count number of results on Google search page?

Solution:- Here we will use “Static type of DP” (by provide the set of properties and values directly) to find the Search results count.
Dim sSearch : sSearch = "UFTHelp.com"

'Function call to fetch the Result count
fnSearch(sSearch)


'*********************Function to count search result*************************
Public Function fnSearch(sInput)
Dim objGoogle,sResult,sCount
'Open the browser with Google.com
SystemUtil.Run "iexplore.exe", "http://www.google.com"

'Creating the object of google page
Set objGoogle = Browser("title:=Google").Page("title:=Google")

'Set value for searching and click on search
If objGoogle.WebEdit("name:=q","type:=text").Exist(4) Then
objGoogle.WebEdit("name:=q","type:=text").Set sInput
End If

' clicking on search
If objGoogle.WebButton("name:=Google Search","type:=submit").Exist(2) Then
objGoogle.WebButton("name:=Google Search","type:=submit").Click
End If



'Fetching the Results count displayed
If Browser("title:=Google").Page("title:=.*Google Search").WebElement("html id:=resultStats").Exist(2) Then
sResult= Browser("title:=Google").Page("title:=.*Google Search").WebElement("html id:=resultStats").GetROProperty("innertext")
Msgbox sResult

End If


'Incase we want exact result we can split the result to fetch the exact value
sCount = split(sResult)
msgbox sCount(1)

End Function


Understanding GetRoProperty

ufthelp

Leave a Reply

Your email address will not be published. Required fields are marked *