zoukankan      html  css  js  c++  java
  • Watir: 右键点击实例(某些如果应用AutoIt来做会更加简单高效)

    require 'watir'
    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 defcreate_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 =begin def main() # Open google index page,and send a right click to the logo image ie = Watir::IE.new() ie.goto('http://www.tsa.gov/travelers/airtravel/prohibited/permitted-prohibited-items.shtm') ie.link(:text, 'Clickhere').focus ie.link(:text, 'Clickhere').right_click # Then, bring up theproperties menu (works with IE6, at least) ie.send_keys("{DOWN}{DOWN}{DOWN}{ENTER}") end if __FILE__ == $0 main end =end
  • 相关阅读:
    2017-2018 ACM-ICPC, Asia Tsukuba Regional Contest E:Black or White
    树状数组--二叉索引树
    P1654 OSU!-洛谷luogu
    P1365 WJMZBMR打osu! / Easy-洛谷luogu
    P4550 收集邮票-洛谷luogu
    P2257 YY的GCD--洛谷luogu

    P3200 [HNOI2009]有趣的数列--洛谷luogu
    catalan数
    lucas定理
  • 原文地址:https://www.cnblogs.com/autotest/p/3262435.html
Copyright © 2011-2022 走看看