51Testing软件测试论坛

标题: 【已解决】高手来!句柄(hwnd)问题 [打印本页]

作者: tmdbt100200    时间: 2012-12-12 10:46
标题: 【已解决】高手来!句柄(hwnd)问题
本帖最后由 黑羽祭 于 2012-12-13 09:14 编辑

Browser("micclass:=Browser").OpenNewTab新建一个窗口,如何让他自动获取新窗口的hwnd,求代码!
作者: 黑羽祭    时间: 2012-12-12 11:24
回复 1# tmdbt100200


    随手写的,没验证,你试试看吧。
  1. Dim newHwnd
  2. Browser("micclass:=Browser").OpenNewTab
  3. newHwnd = Browser("micclass:=Browser","CreationTime:=1").GetROProperty("hwnd")
  4. msgbox newHwnd
复制代码

作者: tmdbt100200    时间: 2012-12-12 18:58
回复 2# 黑羽祭


    谢谢楼主问答,妄确,不愧为楼主,但我想问下,楼主是如何知道用CreationTime:=1这个方法的呢?哪本书里有还是从其他方面得知,望告诉,谢谢
作者: 黑羽祭    时间: 2012-12-13 09:13
本帖最后由 黑羽祭 于 2012-12-13 09:14 编辑

回复 3# tmdbt100200


    妄确是神马?楼主?你这是变相夸自己啊~
    我是以前刚开始玩QTP的时候在对象库里发现的这个属性,然后上网查的的内容
关于CreationTime,在帮助文档里详细的说明:
Identifying an Object Using the CreationTime Property
While learning a browser object, QuickTest assigns a value to the CreationTime identification property. This value indicates the order in which the browser was opened relative to other open browsers. The first browser that opens receives the value CreationTime = 0.

During the run session, if QuickTest is unable to identify a browser object based solely on its test object description, it examines the order in which the browsers were opened, and then uses the CreationTime property to identify the correct one.

For example, if QuickTest learns three browsers that are opened at 9:01 pm, 9:03 pm, and 9:05 pm, QuickTest assigns the CreationTime values, as follows: CreationTime = 0 to the 9:01 am browser, CreationTime = 1 to the 9:03 am browser, and CreationTime = 2 to the 9:06 am browser.

At 10:30 pm, when you run a test or component with these browser objects, suppose the browsers are opened at 10:31 pm, 10:33 pm, and 10:34 pm. QuickTest identifies the browsers, as follows: the 10:31 pm browser is identified with the browser test object with CreationTime = 0, 10:33 pm browser is identified with the test object with CreationTime = 1, 10:34 pm browser is identified with the test object with CreationTime = 2.

If there are several open browsers, the one with the lowest CreationTime is the first one that was opened and the one with the highest CreationTime is the last one that was opened. For example, if there are three or more browsers open, the one with CreationTime = 2 is the third browser that was opened. If seven browsers are opened during a recording session, the browser with CreationTime = 6 is the last browser opened.

If a step was created on a Browser object with a specific CreationTime value, but during a run session there is no open browser with that CreationTime value, the step will run on the browser that has the highest CreationTime value. For example, if a step was created on a Browser object with CreationTime = 6, but during the run session there are only two open browsers, with CreationTime = 0 and CreationTime = 1, then the step runs on the last browser opened, which in this example is the browser with CreationTime = 1.
作者: xjwldlover    时间: 2012-12-13 10:17
--补充--
可以通过两种方式获取browser的hwnd
Browser("micclass:=Browser","CreationTime:=1").GetROProperty("hwnd")
Browser("micclass:=Browser","CreationTime:=1").Object.HWND
如果是通过vbs进行对象的判断,使用第二个;如果使用qtp进行对象识别(QTP对象操作),则使用第一个。
作者: slxmikesong    时间: 2012-12-13 10:43
回复 2# 黑羽祭
版主,我的OpenNewTab为什么就不好使呢。。。环境:QTP11.0+Win7+IE8.0
作者: 黑羽祭    时间: 2012-12-13 11:08
回复 6# slxmikesong


你试试开一个IE页面的情况下运行   
browser(":=").OpenNewTab
如果还不行,就写详细一些,然后发个贴吧




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