Facebook

For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
Selenium+Appium 16th October 2017 7.30 AM - 9.00 AM IST 45 Days ClassRoom + Online Mind Q Madhapur
Selenium+Appium 30th October 2017 9.30 AM - 11.00 AM IST 45 Days ClassRoom + Online Mind Q Madhapur

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Monday, April 1, 2013

Sample DOM Script On Google Search

Here i am giving a sample DOM Script on google search.
Copy the script, paste in a notepad, save as a vbs file and double click on it.
This script will run without QTP.

'Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'********************************************************
'Script
'********************************************************
Set IE=CreateObject("internetexplorer.application")
IE.Visible=True
IE.Navigate "http://google.com"
BrowserSync(IE)

Set PageObject=IE.Document

'Set Value in Google Search Edit Box
SetValueinEditBox PageObject,"q","qtp sudhakar"
'Click on Google Search Button
ClickButton PageObject,"Google Search"
BrowserSync(IE)
'Click on Result Link
ClickLink PageObject,"http://qtpsudhakar.com/"

MsgBox "Completed"

'********************************************************
'Functions
'********************************************************
Function SetValueinEditBox(PageObject,EditName,Value2Set)

    Dim EditObjects
    Dim Edit

    set EditObjects=PageObject.getElementsByTagName("INPUT")
        
    For each Edit in EditObjects

        If lcase(Edit.name)=lcase(EditName) and lcase(Edit.type)="text" then
            Edit.value=Value2Set
            Exit for
        End If

    Next

    Set EditObjects= Nothing
    Set Edit=Nothing

End Function
'********************************************************
'********************************************************
Function ClickButton(PageObject,ButtonValue)

    Dim ButtonObjects
    Dim button
    Dim ButtonClicked
    set ButtonObjects=PageObject.getElementsByTagName("INPUT")
        
    For each button in ButtonObjects

        If lcase(button.type)="button" Or lcase(button.type)="submit" Then
            If LCase(button.value)=LCase(ButtonValue) Then
                button.click
                ButtonClicked=true
            Exit For
            End if
        End If

    Next

    If Not ButtonClicked=True Then
    
    set ButtonObjects=PageObject.getElementsByTagName("button")
        
    For each button in ButtonObjects

            If LCase(button.value)=LCase(ButtonValue) Then
                button.click
                ButtonClicked=true
    Exit For
   End If

    Next
    
    End if
    Set ButtonObjects= Nothing
    Set button=Nothing

End Function
'********************************************************
'********************************************************
Function ClickLink(PageObject,LnkURL)

    Dim lnkObjects
    Dim lnk

    set lnkObjects=PageObject.getElementsByTagName("a")
       
    For each lnk in lnkObjects

        If lcase(lnk.href)=lcase(LnkURL) then
            lnk.click
            Exit for
        End If

    Next

    Set lnkObjects= Nothing
    Set lnk=Nothing

End Function
'********************************************************
'********************************************************
Function BrowserSync(BrowserObj)

Dim oTimeout,oTime
oTimeout=10
WScript.Sleep 1000
For oTime=1 to oTimeout
    If BrowserObj.ReadyState=4 Then
        Exit For
    Else
        WScript.Sleep 1000
    End If
Next 

End Function
'********************************************************
'********************************************************
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~End  

5 comments :

  1. Greate Scripts...................

    ReplyDelete
  2. Hi Sudhakar,
    I am unable to select particular value from dropdown list in DOM script.
    Please help

    ReplyDelete
  3. Hi,Can u explain wats the purpose of this DOM model in real time and in which scenarios we will use it

    ReplyDelete