51Testing软件测试论坛

标题: 遇到一个对象不支持方法的问题 [打印本页]

作者: jaunty    时间: 2008-4-25 16:12
标题: 遇到一个对象不支持方法的问题
看下面这段代码
我拿酷讯网站做的实验
我想把innertext的 属性赋值给 lowestprice这个变量 并且希望以msgbox 的形式弹出 那个字符串
但是我运行后总在赋值的那行出错
帮忙给看一下

If Browser("酷讯机票 - 特价机票、比价机票、打折机票、机票查询,酷讯生").Page("广州-北京机票查询结果 - 特价机票、比价机票、打折机票、机").Image("name:=loading").Exist = false then
   
   Dim LowestPrice
   LowestPrice = Browser("酷讯机票 - 特价机票、比价机票、打折机票、机票查询,酷讯生").Page("广州-北京机票查询结果 - 特价机票、比价机票、打折机票、机").WebElement("html tag:=STRONG","innertext=989元").GetROProperty("innertext)
        MsgBox(LowestPrice)
End If

错误信息为:
Object doesn't support this property or method: 'Browser(...).Page(...).WebElement'
Line (25): "LowestPrice = Browser("酷讯机票 - 特价机票、比价机票、打折机票、机票查询,酷讯生").Page("广州-北京机票查询结果 - 特价机票、比价机票、打折机票、机").WebElement("html tag:=STRONG","innertext=989元").GetROProperty("innertext")".

[ 本帖最后由 jaunty 于 2008-4-25 17:04 编辑 ]
作者: xueboy118    时间: 2008-4-25 16:26
试一下这样的写法
Dim LowestPrice
   LowestPrice = Browser("酷讯机票 - 特价机票、比价机票、打折机票、机票查询,酷讯生").Page("广州-北京机票查询结果 - 特价机票、比价机票、打折机票、机").WebElement("html tag:=STRONG","innertext=989元").GetROProperty("innertex")
        MsgBox cstr(LowestPrice)
或许这样可行
作者: hsjzfling    时间: 2008-4-25 16:38
LowestPrice = Browser("酷讯机票 - 特价机票、比价机票、打折机票、机票查询,酷讯生").Page("广州-北京机票查询结果 - 特价机票、比价机票、打折机票、机").WebElement("html tag:=STRONG","innertext=989元").GetROProperty("innertex").ToString

这句中两个错误
1、 .ToString应该去掉
2、 GetROProperty("innertex")应改为GetROProperty("innertext")

建议
耐心多看帮助,细心
作者: xueboy118    时间: 2008-4-25 16:44
还是hsjzfling细心啊,第二个错误我没有留意到,呵呵
作者: jaunty    时间: 2008-4-25 16:55

我就忘记补了几句话

Tostring 之前没有 也是遇到这个错误
然后我害怕是因为返回值变量不是完全的字符串 于是我又强行加了个tostring

那个GetROProperty("innertext") 那个我发上来之前我发现了 但是我想这个问题影响不了这个对象之不支持这个方法
所以就没改

不好意思

[ 本帖最后由 jaunty 于 2008-4-25 17:07 编辑 ]
作者: 没有蛀牙    时间: 2008-4-25 16:56
这个Tostring可不是C#里的Tostring
QTP里是把对象转化成字符形式
HELP里的描述:
Return Value
A String value. The name of the test object and its generic type, for example, MyButton VirtualButton.
Example:
Sub ReportRectangle(obj)

x = obj.GetTOProperty("x")

y = obj.GetTOProperty("y")

w = obj.GetTOProperty("width")

h = obj.GetTOProperty("height")

Reporter.ReportEvent micDone, obj.ToString() & " dimensions", "The Virtual object " & obj.ToString() & " is defined using the following dimensions:
" & x & ", " & y & ", " & x+w & ", " & y+h

End Sub
作者: jaunty    时间: 2008-4-25 17:04
原帖由 没有蛀牙 于 2008-4-25 16:56 发表
这个Tostring可不是C#里的Tostring
QTP里是把对象转化成字符形式
HELP里的描述:
Return Value
A String value. The name of the test object and its generic type, for example, MyButton VirtualButton.
E ...


谢谢你的指导
我又学会一个知识点

不过tostring去掉 也会出那个错  不懂
开始我以为是webelement不支持getroproperty的方法呢
作者: xueboy118    时间: 2008-4-25 17:16
我刚有看了看你的代码,结果又发现个问题,看来你比我还粗心啊,呵呵
LowestPrice = Browser("酷讯机票 - 特价机票、比价机票、打折机票、机票查询,酷讯生").Page("广州-北京机票查询结果 - 特价机票、比价机票、打折机票、机").WebElement("html tag:=STRONG","innertext=989元").GetROProperty("innertext")
这个代码中"innertext=989元"你少写了个“”呵呵
作者: jaunty    时间: 2008-4-25 17:26
是啊  刚才有人帮我也看了 都是手输得  看来还是需要多加小心
但是这个iDE 只能识别错误 不能详细定位错误让人很无语
很谢谢楼上的 !!!
作者: xueboy118    时间: 2008-4-25 17:36
呵呵 不客气 QTP定位错误确实不是很理想,只能定位到具体的某已条语句,至于是语句中的什么错误们就不能很好的定位了,只有靠自己平时积累的经验来判断了,不过想你犯的这个错误,只要自己在细心一点,是完全可以避免的




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2