我的UFT代码无法识别浏览器/父对象。不断获取“找不到父对象”

时间:2018-09-03 18:53:24

标签: vbscript hp-uft

我是一名软件自动化专业的学生,​​是编程的新手。我只写了大约几周的代码。我使用的自动化工具是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

1 个答案:

答案 0 :(得分:1)

Page(“ micclass:= Browser”)这是错误的。页面类型的对象也不能同时是浏览器类型。 (micclass是对象的类型)

如果您不想在对象存储库层次结构中使用页面,则只需使用index:= 0即可识别页面