google搜索 站内搜索                 软件测试门户 | 软件测试培训 | 文章资料精选 | 软件测试论坛 | 测试解决方案 | 软件测试博客 | 测试招聘求职 
打印

[求助] 如何判定WebEdit内的Value是否被选中?

如何判定WebEdit内的Value是否被选中?


代码:
Dim tempObj
set tempObj = Browser("CreationTime:=0").Page("index:=").WebEdit("name:=TextboxUserCode")
tempObj.Object.focus()
tempObj.Object.select()
接下来我想做一个CheckPoint,判断WebEdit内的Value是否已经被选中了。
请大家指导一下,谢谢。

TOP

continues your script
dim temp
temp = empObj.Object.GetROProperty("value")
if temp = ExpectedResult then
the action you want to take
Else
maybe should call a log function
end if
乱写的,你看看是不是这个思路可以

TOP

很感谢你的回复,不过你可能没有明白我的意思。
GetROProperty取到的值与控件内选中的值没有关系。也就是选不选中,它取到的值应该都是一样的。
而我的目的是取到选中的值,或是判定控件内的值有没有被选中。
例如:控件内的值是"jinsen",现在"jin"被选中了,使用GetROProperty只能得到"jinsen",而我想要的是"jin"。

TOP

回复 3# 的帖子


SetSelection可以解决你的问题吗?

Sub SetSelection_Example()
'The following example uses the SetSelection method to mark a selection
'of text in an edit box (the second character to the fifth character
'inclusive). The example then chooses Copy from a context menu to copy the
'selected text. Then it chooses Paste in the context menu of a second
'edit box to paste the selected text into the second edit box.

Dialog("Common Controls").WinEdit("Position").SetSelection 1, 4
Dialog("Common Controls").WinEdit("Position").Click 14, 7, 1
Dialog("Common Controls").WinEdit("Position").WinMenu("ContextMenu").Select "Copy"
Dialog("Common Controls").WinEdit("Offset").Click 18, 7, 1
Dialog("Common Controls").WinEdit("Offset").WinMenu("ContextMenu").Select "Paste"
End Sub

TOP

谢谢,也许你说的方法能用,但是SetSelection是只针对WinEdit的,我想要的是WebEdit的。

TOP

用WSH传个CTRL+A快捷键呢?

TOP

我感觉这个过程是在测试QTP软件本身。
既然用select方法选中了包含的文字,现在又找方法去验证刚才QTP给自己做的事情对不对!

目前我还没有发现合适的方法。。
引用:
原帖由 jinsen 于 2007-11-22 15:14 发表
代码:
Dim tempObj
set tempObj = Browser("CreationTime:=0").Page("index:=").WebEdit("name:=TextboxUserCode")
tempObj.Object.focus()
tempObj.Object.select()
接下来我想做一个CheckPoint,判断WebEdit内 ...
http://www.abfun.cn 北京测试圈
http://www.abfun.cn 北京测试圈

TOP

其实,原来的情况是在FocusIn的时候,会自动选中WebEdit内的值。
这里,我只是把它适用于所有的网页。

TOP

一个傻办法
你把选中的剪切掉,然后判断剪切板里的

TOP

如果这只是过程中的一步的话。。 checkpoint没什么必要。。
如果这个是需要验证的地方的话。 在其步骤下面一定有其他的操作。。 不会光全选了内容就完事了吧。。 所以checkpoint应该可以加在后面的步骤上

TOP

回复 10# 的帖子


同意楼上
个人主页:扬起测试的风帆

TOP

把简单的事复杂化......

TOP

问题终于解决了,以下是解决方法:
Dim pageObj,txt,myWebEditObj,myTextRange,strTemp
'画面对象
Set pageObj = Browser("CreationTime:=0").Page("index:=")
'控件对象
Set myWebEditObj = Browser("CreationTime:=0").Page("index:=").WebEdit("name:=TextboxUserCode")
'选中控件中的文字
myWebEditObj.Object.select()
'取得画面上选中的对象
Set txt = pageObj.Object.selection
'取得画面上选中的对象的文字对象
Set strTemp = txt.createRange
'取得画面上控件选中的文字对象
Set myTextRang = myWebEditObj.Object.createTextRange
'比较
If strTemp.isEqual(myTextRang) Then
        msgBox "true"
Else
        msgBox "false"
End If

TOP

Page("index:=") 这样写没有问题吗?
实践是检验真理的唯一标准。

TOP

没有问题。这段代码我在本机上已经运行通过了。
个人认为这个“Page”在Web描述性语言的测试中并不起什么作用,只是为了QTP能运行通过,我还曾经在只打开一个页面的情况下,写成“Index:=9”,它在运行时也没有出错。
上述观点只是我个人的看法,有什么不对的地方,请大家指正。

TOP

 
当前时区 GMT+8, 现在时间是 2008-12-5 23:47Copyright(C)上海博为峰软件技术有限公司 2001-2007 电话:021-64471599-8017
当您在访问网站、论坛及博客过程中遇到问题时可发送email:webmaster@51testing.com或发送论坛短信至管理员风在吹