本文主要是介绍右击鼠标事件的实现(QTP及Ruby),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
QTP实现:
‘———–about——————
‘ @funcname:Common_MicRightMouse
‘ @brief: QTP右击鼠标选择菜单并回车
‘ @param:obj:具体的操作对象; rows:第几行菜单;
‘ @rtnval:无
‘ @register:无
‘ @register方式:无
Public Function Common_MicRightMouse(obj,rows)
’set obj= Browser(”浏览器”).Page(”member/login_登录页面”).WebElement(”登录页面空白处”)
‘拿到环境变量配置文件
cur_replay_type = Setting.WebPackage(”ReplayType”)
‘修改类型为鼠标右击
Setting.WebPackage(”ReplayType”) = 2
‘执行右击操作
obj.Click 123, 63,micRightBtn
‘环境变更还原
Setting.WebPackage(”ReplayType”) = cur_replay_type
idx=rows
‘模拟键盘操作
Set keys_test=createobject(”wscript.shell”)
‘通过循环语句,查找右击菜单的位置
For i = 1 To idx
keys_test.sendkeys “{down}”
NEXT
‘并回车
keys_test.sendkeys “{enter}”
‘退出操作
Set keys_test = nothing
End Function
Ruby实现:
module Watir
class Element
def top_edge
assert_exists
assert_enabled
ole_object.getBoundingClientRect.top.to_i
end
def top_edge_absolute
top_edge + page_container.document.parentWindow.screenTop.to_i
end
def left_edge
assert_exists
assert_enabled
ole_object.getBoundingClientRect.left.to_i
end
def left_edge_absolute
left_edge + page_container.document.parentWindow.screenLeft.to_i
end
def right_click
x = left_edge_absolute
y = top_edge_absolute
#puts "x: #{x}, y: #{y}"
WindowsInput.move_mouse(x, y)
WindowsInput.right_click
end
end
end
module WindowsInput
# Windows API functions
SetCursorPos = Win32API.new('user32','SetCursorPos', 'II', 'I')
SendInput = Win32API.new('user32','SendInput', 'IPI', 'I')
# Windows API constants
INPUT_MOUSE = 0
MOUSEEVENTF_LEFTDOWN = 0x0002
MOUSEEVENTF_LEFTUP = 0x0004
MOUSEEVENTF_RIGHTDOWN = 0x0008
MOUSEEVENTF_RIGHTUP = 0x0010
module_function
def send_input(inputs)
n = inputs.size
ptr = inputs.collect {|i| i.to_s}.join # flatten arrays into single string
SendInput.call(n, ptr, inputs[0].size)
end
def create_mouse_input(mouse_flag)
mi = Array.new(7, 0)
mi[0] = INPUT_MOUSE
mi[4] = mouse_flag
mi.pack('LLLLLLL') # Pack array into a binary sequence usable to SendInput
end
def move_mouse(x, y)
SetCursorPos.call(x, y)
end
def right_click
rightdown = create_mouse_input(MOUSEEVENTF_RIGHTDOWN)
rightup = create_mouse_input(MOUSEEVENTF_RIGHTUP)
send_input( [rightdown, rightup] )
end
end
这篇关于右击鼠标事件的实现(QTP及Ruby)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!