[img]http://dl.iteye.com/upload/attachment/212121/bae91be8-bebf-305b-9477-bd02d311b451.jpg[/img]
用Watir点击类似于上图的提示条。
首先引用前面一片文章提到过的模拟鼠标操作的一个模块。
然后通过DOM得到坐标,直接点击……
剩下的事情就根据具体请过具体解决了……
用Watir点击类似于上图的提示条。
首先引用前面一片文章提到过的模拟鼠标操作的一个模块。
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
def left_click
leftdown = create_mouse_input(MOUSEEVENTF_LEFTDOWN)
leftup = create_mouse_input(MOUSEEVENTF_LEFTUP)
send_input( [leftdown, leftup] )
end
end
然后通过DOM得到坐标,直接点击……
require 'watir'
require 'Win32API'
require 'WindowsInput'
ie = Watir::IE.attach(:title, "test page")
ie.bring_to_front
x = ie.document.parentWindow.screenLeft.to_i + 10
y = ie.document.parentWindow.screenTop.to_i - 10
WindowsInput.move_mouse(x, y)
WindowsInput.left_click
剩下的事情就根据具体请过具体解决了……