我是一名软件自动化专业的学生,也是编程新手。我只编写了几周的代码。我使用的自动化工具是UFT,语言是VB脚本
当我在UFT中编写脚本时,我有时会遇到这个错误:
Cannot find the "[ WebList ]" object's parent "[ Browser ]" (class Browser). Verify that parent properties match an object currently displayed in your application.
Line (32): "Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("html id:=state", "html tag:=SELECT").Select State".
我知道这意味着UFT无法识别浏览器或页面。我不知道的是为什么。我以为我正确编写了代码。我甚至在浏览器和页面中添加了创建时间和标题以更好地识别它。
任何人都可以帮我解决这个错误吗?
这是我的整个脚本。它很短,只有54行。
选项明确
Dim MyExcel, MySheet, RowCount, i ,IE, URL, State, PayType, Pay, PayFrequency, MaritalStatus, WithholdingAllowances, AdditionalWithholding, Allowances, AdditionalWithholding2, ActualCheckValue, ExpectedCheckValue, CapturedTaxRate
Set MyExcel = CreateObject ("Excel.Application")
MyExcel.Workbooks.Open "C:\Users\PIIT\Documents\Excel Docs\In Class Assigment - 7.xlsx"
Set MySheet = MyExcel.ActiveWorkbook.WorkSheets ("Sheet1")
IE = "iexplore.exe"
URL = "suburbancomputer.com/tips_calculator.php"
SystemUtil.CloseProcessByName IE
SystemUtil.Run IE, URL
wait 5
RowCount = MySheet.UsedRange.Rows.Count
For i = 2 To RowCount
State = MySheet.Cells(i,"A")
PayType = MySheet.Cells(i,"B")
Pay = MySheet.Cells(i,"C")
PayFrequency = MySheet.Cells(i,"D")
MaritalStatus = MySheet.Cells(i,"E")
WithholdingAllowances = MySheet.Cells(i,"F")
AdditionalWithholding = MySheet.Cells(i,"G")
Allowances = MySheet.Cells(i,"H")
AdditionalWithholding2 = MySheet.Cells(i,"I")
ActualCheckValue = MySheet.Cells(i,"J")
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("html id:=state", "html tag:=SELECT").Select State
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("innertext:=Salary Hourly ", "html tag:=SELECT").Select PayType
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebEdit("html id:=salary", "html tag:=INPUT").Set Pay
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("html id:=ppy", "html tag:=SELECT").Select PayFrequency
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("html id:=fit_marital_status", "html tag:=SELECT").Select MaritalStatus
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("html id:=fit_dependent", "html tag:=SELECT").Select WithholdingAllowences
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebEdit("html id:=fit_addon", "html tag:=INPUT").Set AdditionalWithholdings
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebList("html id:=state_dependent", "html tag:=SELECT").Select Allowences
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebEdit("html id:=state_addon", "html tag:=INPUT").Set AdditionalWithholding2
Browser("micclass:=Browser", "CreationTime:=0", "Title:=.*").Page("micclass:=Browser", "CreationTime:=0", "Title:=.*").WebButton("name:=Calculate Paycheck", "class:=nav_button").Click
wait 2
ActualCheckValue = Browser("micclass:=Browser").Page("micclass:=Page").Page("micclass:=Page").WebElement("html tag:=B", "index:=16").GetROProperty("innerhtml")
Print ActualCheckValue
Browser("micclass:=Browser").Page("micclass:=Page").Page("micclass:=Page").Link("html id:=ui-id-3", "innerhtml:=Effective Rate").Click
CapturedTaxRate = Browser("micclass:=Browser").Page("micclass:=Page").Page("micclass:=Page").WebElement("html tag:=B", "index:=21").GetROProperty("innerhtml")
Print CapturedTaxRate
Browser("micclass:=Browser").Page("micclass:=Page").Page("micclass:=Page").Link("html id:=ui-id-1", "innerhtml:=Enter").Click
Next
Page(“micclass:= Browser”)这是错误的。页面类型的对象也不能是类型浏览器。 (micclass是Object的类型)
要识别Pages,只需使用index:= 0,如果您不想在Object Repository层次结构中使用它们