Count No of Links in Google

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Rakesh123
Posts: 72
Joined: Thu Oct 28, 2010 2:18 pm

Count No of Links in Google

Post by Rakesh123 » Sun Sep 09, 2012 2:58 pm

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

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: Count No of Links in Google

Post by sham526 » Mon Sep 10, 2012 10:03 am

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

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: Count No of Links in Google

Post by sham526 » Tue Sep 18, 2012 6:57 am

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")