Win7 IE9下QTP11中FireEvent与SendKeys的使用实践

环境:Win7+IE9+QPT11

问题描述:

WebList选择值,选择的类别自动在table中显示。尝试如下:

一、使用 FireEvent "onchange" 方法(经验证此方法在本环境下无效,如要使用将QTP升级到11.5即可),代码如下:

Browser("Browser").Page("Page").WebList("WebList").Select "val0"
Browser("Browser").Page("Page").WebList("WebList").FireEvent "onchange"

附:FireEvent可用事件有: onchange, onclick, ondblclick, onblur, onfocus, onmousedown,onmouseup, onmouseover, onmouseout, onsubmit, onreset, onpropertychange.

二、使用SendKeys方法,代码如下

1.最小化QTP

Set QTP= CreateObject("QuickTest.Application")
QTP.WindowState = "Minimized"

2.控件获得焦点,发送按键

Set ks=CreateObject("WScript.Shell")
Browser("Browser").Page("Page").WebList("WebList").Object.focus
ks.SendKeys "{UP}

附:

1.程序窗口显示状态介绍:

object.WindowState [= value]

value可取如下值

  • Maximized--UFT is displayed at full screen size.
  • Minimized--UFT is open, but minimized.
  • Normal--UFT is displayed at the size it was prior to the last minimize or maximize operation. 

官方示例:

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start UFT

qtApp.ActivateView "ExpertView" ' Display the Editor
qtApp.Options.DisplayKeywordView = False ' Hide the Keyword View
qtApp.ShowPaneScreen "ActiveScreen", True ' Display the Active Screen pane
qtApp.ShowPaneScreen "DataTable", False ' Hide the Data Table Explorer pane
qtApp.ShowPaneScreen "DebugViewer", True ' Display the Debug Watch pane
qtApp.WindowState = "Maximized" ' Maximize the UFT window
qtApp.Visible = True ' Make the UFT window visible

Set qtApp = Nothing ' Release the Application object


2.按键对应描述:

按键参数

BACKSPACE

{BACKSPACE}, {BS}, or {BKSP}

BREAK

{BREAK}

CAPS LOCK

{CAPSLOCK}

DEL or DELETE

{DELETE} or {DEL}

DOWN ARROW

{DOWN}

END

{END}

ENTER

{ENTER} or ~

ESC

{ESC}

HELP

{HELP}

HOME

{HOME}

INS or INSERT

{INSERT} or {INS}

LEFT ARROW

{LEFT}

NUM LOCK

{NUMLOCK}

PAGE DOWN

{PGDN}

PAGE UP

{PGUP}

PRINT SCREEN

{PRTSC}

RIGHT ARROW

{RIGHT}

SCROLL LOCK

{SCROLLLOCK}

TAB

{TAB}

UP ARROW

{UP}

F1

{F1}

F2

{F2}

F3

{F3}

F4

{F4}

F5

{F5}

F6

{F6}

F7

{F7}

F8

{F8}

F9

{F9}

F10

{F10}

F11

{F11}

F12

{F12}

F13

{F13}

F14

{F14}

F15

{F15}

F16

{F16}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值