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
Count No of Links in Google
Re: Count No of Links in Google
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
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
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")
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")