使用DP,QTP却提示对象在OR中未找到...
本帖最后由 kar1 于 2012-4-6 02:10 编辑刚接触QTP,如下想检查某些链接和图片是否在页面中存在,执行后再判断n、p值为true还是false:
Set objPage = Browser("title:=.*").Page("title:=.*")
n = objPage.Image("logo").exist(3)
p = objPage.Link("Profile").exist(3)
debug时看到objPage已经取得,但是QTP总是提示:
"The "logo"object was not found in the Object Repository.
Check the Object Repository to confirm that the object exists or to find the correct name for the object."
下一行的Link也提示在OR里找不到。难道必须要把需要检查的object全都储存到OR里才可以吗?
我试过把对象加到OR里,的确能用,但格式是类似Browser("title:=home").Page("title:=home").Image("logo").exist,页面title被定死了,有没有办法写一个通用的语句来检查页面元素?请高手们指教! 对于这种采用描述性编程的角本是不需要把检查对像存储在OR里的,只要在实际运行中存在就能被检查出来,,
你可以采用以下方法来实现:
dim testobj
testobj = inputbox("please enter the object text name you wanna tested“)
webelementCheck(testobj)
public function webelementCheck(object)
dim ob, obj,i
ob("micclass").value = "xxx"
ob("html tag").value = "xxx"
...
set obj = Browser("title:=home").Page("title:=home").childobject(ob)
for i = 0 to obj.count-1 step xx
if obj(i).GetROProperty("title") = object then
reporter.ReportEvent micPass, "Pass","step pass"
....
else
reporter.ReportEvent micfail, "failed","step failed"
end if
end function
这样就能满足你的要求了 父对象objPage用的是描述性编程,子对象Image和Link也得用描述性编程 帖子审核了一天多,我都忘了还有这帖子了...
多谢三楼提醒!我知道错在哪里了:)
二楼的注意很不错,我稍微做了一点修改,这下能用了:
webElementCheck "logo\.jpg", "Image", "file name"
public function webElementCheck(objText, objType, roProp)
dim ob, obj,i
Set ob = Description.Create()
ob("micclass").value = objType
'ob("html tag").value = "SPAN"
set obj = Browser("title:=.*").Page("title:=.*").childobjects(ob)
For i = 0 to obj.count-1' step xx
'msgbox obj(i).GetROProperty("name")
if StrComp(obj(i).GetROProperty(roProp), objText, 0) then
blnFlag = true
Exit for
else
blnFlag = false
end if
next
If blnFlag Then
reporter.ReportEvent micPass, "Check " + objType + ": " + objText, "Passed"
else
reporter.ReportEvent micfail, "Check " + objType + ": " + objText, "Failed"
End If
end function
谢谢两位!
页:
[1]