Get TooTip text from Java Table
JavaWindow(“abc”).JavaTable(“xyz”).Object.setColumnSelectionAllowed=False
JavaWindow(“abc”).JavaTable(“xyz”).Object.setRowSelectionAllowed=False
JavaWindow(“abc”).JavaTable(“xyz”).ClickCell”#1″,”#0″
set obj=JavaWindow(“abc”).JavaTable(“xyz”).Object.getCellRect(1,0,True)
JavaWindow(“abc”).JavaTable(“xyz”).FireEvent micMouseMove,0, “BUTTON1_MASK”, obj.x, obj.y, 1, “OFF”
msgbox JavaWindow(“abc”).JavaObject(“toolkit class:=javax\.swing\.JToolTip
“).Object.tipText
How to Download a file using VbScript
Following is the code to download a file using Vbscript, without using QTP
This code uses the HTMLDom and URLDownloadToFile method from urlmon API.
Since VBScript does support calling Native API methods directly, here I am using Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript
Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file
Private Declare Function URLDownloadToFile Lib “urlmon” Alias _
“URLDownloadToFileA” ( _
ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Sub FileSave(strUrl, Des)
r = URLDownloadToFile(0, strUrl, Des, 0, a)
End Sub
Step2: Create a VBS and copy the below code and change the file paths
Set ie = CreateObject(“InternetExplorer.Application”)
ie.navigate “www.google.com”
ie.Visible = True
WScript.Sleep 3000
ie.document.all.q.Value = “Testing + doc”
ie.document.all.btnG.Click
WScript.Sleep 1000
Set obj = ie.document.getElementsByTagName(“A”)
For i = 0 To obj.Length
If obj(i).innerText = “Testing Document” Then
hr = obj(i).href
Exit For
End If
Next
arrhr = Split(hr, “/”)
fname = arrhr(UBound(arrhr))
If hr <> “” Then
strUrl = hr
Des = “C:\Documents and Settings\Desktop\” & fname
Set objXL = CreateObject(“Excel.Application”)
With objXL.Application
.Visible = False
‘Open the Workbook
.Workbooks.Open “C:\Documents and Settings\Desktop\Download.xls”
‘Include CARMA in menu, run AutoOpen
objXL.Application.DisplayAlerts = False
x = .Run(“FileSave”, strUrl, Des)
End With
Set objXL = Nothing
MsgBox “Download Completed , the location of the saved file is->” & Des
End If
Set ie = Nothing
‘Special Thanks to Chandan Ray
Search for a particular value in Excel
Set appExcel = CreateObject(“Excel.Application”)
appExcel.visible=true
Set objWorkBook = appExcel.Workbooks.Open (filepath)’opens the sheet
Set objSheet = appExcel.Sheets(“Sheet1”)’ To select particular sheet
With objSheet.UsedRange ‘ select the used range in particular sheet
Set c = .Find (“nn”)’ data to find
For each c in objSheet.UsedRange’ Loop through the used range
If c=”nn” then’ compare with the expected data
c.Interior.ColorIndex = 40′ make the gary color if it finds the data
End If
Set c = .FindNext(c)’ next search
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing
Author:Mohan Kakarla
Copy an excel sheet to another excel
Following is the code to copy the conntents of a sheet in one excel to another excel sheet
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\2.xls”)
objWorkbook1.Worksheets(“Sheet1”).UsedRange.Copy
objWorkbook2.Worksheets(“Sheet1”).Range(“A1”).PasteSpecial Paste =xlValues
objWorkbook1.save
objWorkbook2.save
objWorkbook1.close
objWorkbook2.close
set objExcel=nothing
Author: Mohan Kakarla
Prompt Dialog For Password Entry In QTP with help of DotNetFactory
The following code popup a dialog with a edit box for a password entry when it run from the QTP
Set objForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form”, “System.Windows.Forms”)
Set objBtn1 = DotNetFactory.CreateInstance(“System.Windows.Forms.Button”, “System.Windows.Forms”)
Set objEdit1 = DotNetFactory.CreateInstance(“System.Windows.Forms.TextBox”, “System.Windows.Forms”)
x=80
y=40
Set p1 = DotNetFactory.CreateInstance(“System.Drawing.Point”,”System.Drawing”,x,y) ‘This will provide the locations(X,Y) for the controls
Set lbl= DotNetFactory.CreateInstance(“System.Windows.Forms.Label”,”System.Windows.Forms”)
lbl.Text=”Enter Password”
lbl.Location=p1
objForm.Controls.Add(lbl)
p1.Y=CInt(lbl.Height)+40
objEdit1.Location=p1
objForm.Controls.Add(lbl)
objEdit1.UseSystemPasswordChar=true’To set the password character From system
objForm.Controls.Add(objEdit1)
objBtn1.Text=”OK”
p1.Y=Cint(p1.Y)+CInt(objEdit1.Height)+20
objBtn1.Location=p1
objForm.CancelButton=objBtn1
objForm.Controls.Add(objBtn1)
objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog
msgbox “The Password You have Entered Is: “&objEdit1.Text
Author: Mohan Kumar Kakarla
OpenFileDialog In QTP with help of DotNetFactory
Set fd = DotNetFactory.CreateInstance(“System.Windows.Forms.OpenFileDialog”, “System.Windows.Forms”)
fd.InitialDirectory=”c:\\”
fd.Filter=”txt files (*.txt)|*.txt |All files (*.*) |*.*”
fd.RestoreDirectory=true
fd.FilterIndex=2
fd.ShowDialog()
msgbox fd.FileName
Author: Mohan Kakarla
Prompt Dialog with Radio buttons in QTP with help of DotNetFactory
The following code popup a dialog with 2 radi button to select an option when it run from the QTP
Set objForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form”, “System.Windows.Forms”)
Set objRd1 = DotNetFactory.CreateInstance(“System.Windows.Forms.RadioButton”, “System.Windows.Forms”)
Set objRd2 = DotNetFactory.CreateInstance(“System.Windows.Forms.RadioButton”, “System.Windows.Forms”)
Set objGb = DotNetFactory.CreateInstance(“System.Windows.Forms.GroupBox”, “System.Windows.Forms”)
Set objBtn2 = DotNetFactory.CreateInstance(“System.Windows.Forms.Button”, “System.Windows.Forms”)
x=10
y=10
Set p1 = DotNetFactory.CreateInstance(“System.Drawing.Point”,”System.Drawing”,x,y) ‘This will provide the locations(X,Y) for the controls
objRd1.Text=”Radio1″
objGb.Location=p1
p1.Y=30
objRd1.Location=p1
p1.Y=CInt(objRd1.Height)+CInt(objRd1.Top)+10
objRd2.Location=p1
objRd2.Text=”Radio2″
objGb.Text=”Select The Radio Button”
objGb.Controls.Add(objRd1)
objGb.Controls.Add(objRd2)
objBtn2.Text=”OK”
p1.X=60
p1.Y=CInt(objGb.Height)+20
objBtn2.Location=p1
objForm.CancelButton=objBtn2
objForm.Controls.Add(objGb)
objForm.Controls.Add(objBtn2)
objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog
If objRd1.Checked Then
msgbox “You have selected Radio 1”
elseif objRd2.Checked Then
msgbox “You have selected Radio 2”
else
msgbox “No Radio button was selected”
End If
Author: Mohan Kumar Kakarla
Run an .exe file and wait till it finish
To run path\abc .exe and wait to contunie with next statement in the .vbs-file until after abc.exe has finished.
add the bWaitOnReturn parameter to the Run statement …
object.Run strCommand, [intWindowStyle], [bWaitOnReturn]
-
Archives
- July 2011 (1)
- March 2011 (1)
- November 2010 (1)
- November 2008 (4)
- October 2008 (2)
- September 2008 (2)
- June 2008 (1)
- March 2008 (4)
- February 2008 (44)
-
Categories
- Automated Test Script Creation Process
- Automating MS Word
- Automating QC
- Automation Object Model For QTP
- Backward compatability in QTP
- Browser Scripts
- COM and QTP
- compare 2 text files
- Descriptive programming
- Descriptive Programming and Child Objetcs
- Dictonary Object
- DotNetFactory
- Excel Automation
- Extra Topics
- Files and Folders
- General Standards to be followed in Test scripts
- New Features In QTP9.5
- QC-OTA
- QTP Additional Faqs
- QTP Faqs
- QTP Naming Convention
- QTP Tips and Faqs
- Running stored procedures from QTP
- Send keyboard keys
- Uncategorized
- Uninstall a software using QTP
- Uninstall a software using vbscript
- Update data in a database
- VBScript and IE Automation
- VBScript Faqs and Useful resources
- What’s New in Quick Test Pro 9.0
- Whats New in QTP 9.5
- XML Scripting
-
RSS
Entries RSS
Comments RSS