Page 1 of 1

Count No of Links in Google

Posted: Sun Sep 09, 2012 2:58 pm
by Rakesh123
Hi Guys,

I am trying to automate simple smple scenario.

I need to enter a text in Google search box & I need to click on "Search' button.

In google main page I need to verify the no. of search items.

For E.g:If I search for "Ranorex" in google,I will get 10 links in first page.So I need to verify whether the no. of links is equal to 10 or not.

Can anyone provide me the code,how to verify this scenario?

Thanks,
Rakesh

Re: Count No of Links in Google

Posted: Mon Sep 10, 2012 10:03 am
by sham526
Can try this:(Using VB.Net)

Process.Start("iexplore.exe","http://www.google.com")
delay.Milliseconds(5000)
Dim Web_doc As WebDocument=Nothing
Dim bool As Boolean=host.Local.TryFindSingle("/dom[@domain='www.google.co.in']",Web_doc)
If bool Then
Dim search_inputtag As InputTag=Web_doc.FindSingle(Of InputTag)(".//input[@title='Google Search']")
search_inputtag.Click()
Keyboard.Press("Ranorex")
delay.Milliseconds(1000)

Click on the search button.
Dim btn_search As InputTag=Web_doc.FindSingle(Of InputTag)(".//input[@tagValue='Google Search']")
btn_search.click()
Web_doc.WaitForDocumentLoaded()
delay.Milliseconds(1000)
'As page was refreshed we need to again create the Document object.
bool=host.Local.TryFindSingle("/dom[@domain='www.google.co.in']",Web_doc)
'Now search for the links(URL)
Dim links_site As IList(Of Unknown) = Web_doc.Find(Of Unknown)(".//div[@id='center_col']/div[1]//cite")
MsgBox(links_site.count.ToString)
End If

Re: Count No of Links in Google

Posted: Tue Sep 18, 2012 6:57 am
by sham526
The one which i mentioned was the shortest and easiest way(i tried a lot of ways before posting).
1)Launch IE and proceed to Google.
2)Input term 'Ranorex' and Click on Search button.
3)Wait till the document loads.(page refresh stops)
4)Dim links_site As IList(Of Unknown) = Web_doc.Find(Of Unknown)(".//div[@id='center_col']/div[1]//cite")