Help in optimizing the script

157 views
Skip to first unread message

RS Jandu

unread,
May 10, 2007, 7:16:39 AM5/10/07
to QTP - Mercury QuickTest Professional - Automated Software Testing
Hi Guys,

I have following script which opens a browser windoe and search PPT's
on google and and download and save one of them.

Could anybody please help me to do it for each PPT link find on the
page and to do same function on each next page.

Thanks in advance! :)

Browser("[ppt] filetype:ppt - Google").Page("[ppt] filetype:ppt -
Google").Link("Efficient and Secure Function").Output
CheckPoint("Efficient and Secure Function")
Browser("[ppt] filetype:ppt - Google").Page("[ppt] filetype:ppt -
Google").Link("Efficient and Secure Function").Click
Browser("[ppt] filetype:ppt - Google").Dialog("File
Download").WinButton("Save").Click
Browser("[ppt] filetype:ppt - Google").Page("[ppt] filetype:ppt -
Google").Sync
Dialog("File Download").Dialog("Save
As").WinToolbar("ToolbarWindow32").Press "Desktop"
Dialog("File Download").Dialog("Save As").WinButton("Save").Click
Dialog("Download complete").WinButton("Close").Click

Dmitry Motevich

unread,
May 13, 2007, 12:19:41 PM5/13/07
to Mercu...@googlegroups.com
Hello, RS Jandu!
You proposed a nice task! :)

I used descriptive programming to get all found results.
This is a key code of my script:

    Set oDescrLink = Description.Create ()
    oDescrLink("html tag").Value = "a"
    oDescrLink("class").Value = "l"
   
    ' get all found results
    Set arrLinks = Browser("Google").Page("Google").ChildObjects(oDescrLink)
    nLinks = arrLinks.Count
   
    For i = 0 to nLinks - 1
       ' Download results from the current link - arrLinks(i)
       ......
    Next

This part of the code gets all link from the current page. You can download every file from the current link.
After that, you have to repeat the iteration - i.e. download all files from the next page (next ten results)...

I hope, my explanations will help you! :)

Also, I'm sending the full source of my Google Dowloader :)

Sub PerformSearch(sQuery)
    '  search for all ppt-files
    Browser("Google").Page("Google").WebEdit("q").Set sQuery
    Browser("Google").Page("Google").WebButton("Google Search").Click
End Sub

Sub SaveResultsFromPage()
    Set oDescrLink = Description.Create()
    oDescrLink("html tag").Value = "a"
    oDescrLink("class").Value = "l"
   
    ' get all found results
    Set arrLinks = Browser("Google").Page("Google").ChildObjects(oDescrLink)
    nLinks = arrLinks.Count
   
    For i = 0 to nLinks - 1
        'MsgBox arrLinks(i).ToString()
        '  save the current result
        arrLinks(i).Click
        'Browser("Google").Page("Google").Sync

        ' Process "File Download" dlg
        ' TODO: add additional verification for the case when file with the current name exists in the folder "Desktop"
        Dialog("File Download").Dialog("SaveAs").WinToolbar("ToolbarWindow32").Press "Desktop"
        Dialog("File Download").Dialog("Save As").WinButton("Save").Click
        Dialog("Download complete").WinButton("Close").Click
    Next
End Sub

PerformSearch "filetype:ppt"

' go through  all the results pages
Do
    SaveResultsFromPage()

    If  Browser("Google").Page("Google").Link("Next").Exist Then
        Browser("Google").Page("Google").Link("Next").Click
    Else
        Exit Do
    End If
Loop

Any questions - welcome! :)
--
Dmitry Motevich,
I'm looking for online/remote job - $0.01/hour
No joking!
Reply all
Reply to author
Forward
0 new messages