Professional Documents
Culture Documents
Sub ChildObjects_Example()
'The following example uses the ChildObjects method to find all the
'list objects on a Web page, and then to select an item in each list.
For i = 0 To NumberOfLists - 1
Lists(i).Select i + 1
Next
End Sub
Find All WebEdit Objects on a Web Page and Set a Value for a Specific One
Sub ChildObjects_Example()
'This is the value of the 'name' property for the WebEdit object we want to find.
ValueToSet = "6549865461"
1
'Create a description object to help retrieve all WebEdit objects in a specific page.
NumberOfEdits = EditCollection.Count
For i = 0 To NumberOfEdits - 1
End If
Next
End Sub
Find Specific WebEdit Objects on a Web Page and Save Their Values in an Excel
File
Sub ChildObjects_Example()
Dim NumberOfEdits
2
Set oDesc = Description.Create()
NumberOfEdits = EditCollection.Count
For i = 0 To NumberOfEdits - 1
Next
End Sub
Sub CheckProperty_Example()
'is not equal to 15, an error message is displayed in the Test Results.
If Item_Count = 15 Then
3
'Remove one item from the list
Else
Reporter.ReportEvent micFail, "Number Of List Items", "The item count in the list
should be 15, not " & Item_Count & "."
End If
End Sub
Sub Select_Example()
End Sub
Sub Select_Example()
'arrival cities.
End Sub
4
Select an Item from a List and Verify Its Selection
Sub Select_Example()
'Check if all items that were selected in the previous steps are
Reporter.ReportEvent micFail, "ExtendSelect", "The list does not contain all of the
selected items."
Else
End If
End Sub
Sub ExtendSelect_Example()
5
'a multiple-selection list in the 1stFlights list.
VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ExtendSelect
"C345"
'or
VbWindow("frmMain").VbWindow("dlgFlights").VbList("lstFlights").ExtendSelect 2
End Sub
Sub Object_Example()
MyWebEdit.focus
End Sub
Sub ToString_Example()
'and uses the ToString method to write the test object (link) names (for example,
'"banner" and "contents") and test object type (for example, "Frame")
'to c:\Links.txt.
6
Set oDesc = Description.Create
For i = 0 To oLinkCollection.Count - 1
Next
ResultFile.Close
End Sub
Include the Test Object Name and Type in the Test Results
Sub ToString_Example()
'the test object's name and generic type in the Test Results.
Reporter.ReportEvent micDone, "We are selecting the fourth item in the " &
ObjectString, ""
End Sub
7
Retrieve the Value of a Property in an Edit Box
Sub GetROProperty_Example()
'This is the value of the 'name' property for the WebEdit we want to find.
EditToSearch = "credit_card_number"
ValueToSet = "6543210123456789"
'Create a description object to help retrieve all WebEdit objects in a specific page.
oDesc("micclass").Value = "WebEdit"
NumberOfEdits = EditCollection.Count
For i = 0 To NumberOfEdits - 1
End If
Next
End Sub
8
Sub GetItem_Example()
'The following example uses the GetItem method to retrieve the names
'of students from an array in order to send them their grades. First
'according to the list size, inserting the each of the student's names
‘into the array. It then uses the GetItem method to retrieve each
ListSize =
Browser("ListOfStudentNames").Page("ListOfStudentNames").WebList("ListOfStudent
Names").GetTOProperty("items count")
Dim NamesArray()
ReDim NamesArray(ListSize - 1)
For i = 1 To ListSize
NamesArray(i - 1) =
Browser("ListOfStudentNames").Page("ListOfStudentNames").WebList("ListOfStudent
Names").GetItem(i)
Next
'The following function uses the array of student names in order to send grades to the
students.
SendGradesByStudentName (NameArray)
End Sub
Sub ChildItem_Example()
9
'The following example uses the ChildItem method to set the second
WebEditObj.Set "Example"
End Sub
Sub ChildItemCount_Example()
Dim NumEdit
End Sub
Sub ColumnCount_Example()
10
End Sub
Sub GetCellData_Example()
End Sub
Sub GetCellData_GetRowWithCellText_Example()
'The following example retrieves the names of all employees that live in
'the same city as John Smith so that he can arrange rides home with them.
'"John Smith". Then it checks the value of the CityColumnn cell to determine
'the city in which John lives. It searches the table cells to find all other
'employees that live in that city. Finally it uses the GetCellData method to
CityColumn = 4
NameColumn = 2
11
RowNumber =
Browser("CorporateEmployees").Page("CorporateEmployees").WebTable("EmployeesT
able").GetRowWithCellText("John Smith")
Set AccommodationsCity =
Browser("CorporateEmployees").Page("CorporateEmployees").WebTable("EmployeesT
able").ChildItem(RowNumber, CityColumn, "WebEdit", 0)
TableRows =
Browser("CorporateEmployees").Page("CorporateEmployees").WebTable("EmployeesT
able").RowCount
'Search for all employees that live in the same city as 'John Smith' and add them to his
ride home list
For i = 1 To TableRows
If CurrentCity.GetROProperty("value") =
AccommodationsCity.GetROProperty("value") Then
EmployeeName =
Browser("CorporateEmployees").Page("CorporateEmployees").WebTable("EmployeesT
able").GetCellData(i, NameColumn)
End If
Next
End Sub
Sub GetRowWithCellText_Example()
'text "Price" and then find the cell in that row that contains
12
'a link and click it.
Link.Click
End Sub
'The following example checks whether the "url" property exists, and, if not,
has_url_prop = HasPropertyURL(Browser("Browser").Page("Page").Link("Continue"))
Err.Raise 91
End If
'
'The following function, used in the above example, uses the GetTOProperties method
'to retrieve the list of properties and values for the Link test object in order
'
'
'PropertyToSearch = "url"
'PropertyExistInTO = False
13
'Set PropertyCollection = LinkObj.GetTOProperties
'
'For i = 0 To PropertyCollection.Count - 1
'
' End If
'
'Next
'
'HasPropertyURL = PropertyExistInTO
'
'End Function
Sub GetTOProperties_Example()
'WebTable.
End Sub
Sub GetTOProperties_Example()
14
'The following example uses the GetTOProperties method to return a
'It then displays the property name and value of each property in
For i = 0 To PropsCount - 1
Next
End Sub
Sub RowCount_Example()
End Sub
15
Option Explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.provider="microsoft.jet.oledb.4.0"
con.open"d:testdata.mdb"
rs.open"select*from emp",con
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop
The database we are using here is MS Access.Before running this script create a table in
MS Acess.
In the above script I used table called "emp" and column names as "v1" and "v2".
The main use of this script is to use testdata of table(which is in database) in the
application.
16
In the above script we are passing values from database to Textboxes in Windows
Application.
Option Explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.open"provider=sqloledb.1;server=localhost;
uid=sa;pwd=;database=testdata"
rs.open"select*from emp",con
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop
Option Explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")
con.open"provider=oraoledb.1;server=localhost;
uid=scott;pwd=tiger;database=testdata"
17
rs.open"select*from emp",con
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop
18