Facebook

For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
Course Name Date Time Duration Type Location
An important update from QtpSudhakar. I stopped giving classroom training in MindQ Systems. I have bigger plans and I want to put an end to regular classroom training because very less people are practicing. From now onwards every session of mine is going to have explanation and practice. Everyone should practice in presence of mine and should go out of classroom with practical knowledge. So I started my own institute AnyTechLabs in Madhapur. Please reach out to +91-8328152362 for course details. Visit AnyTechLabs.com for address details.
Selenium + Cucumber 24th October 7.30 AM IST to 9.00 AM IST 45 Days WeekDay Online

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