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

Watir: 右键点击实例(某些如果应用AutoIt来做会更加简单高效)的更多相关文章

  1. 常见26个jquery使用技巧详解(比如禁止右键点击、隐藏文本框文字等)

      来自:http://www.xueit.com/js/show-6015-1.aspx 本文列出jquery一些应用小技巧,比如有禁止右键点击.隐藏搜索文本框文字.在新窗口中打开链接.检测浏览器. ...

  2. Python3 tkinter基础 Frame event.x 输出鼠标左右键点击的位置

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. angular5 自定义指令 输入输出 @Input @Output(右键点击事件传递)

    指令写法,angular5官网文档给的很详细. 首先要创建一个文件,需注意命名规范(后缀名为xxx.directive.ts): 今天要记录的是在多个li中,右键点击之后显示出对应的菜单,直接上图吧! ...

  4. 如何在Macbook苹果笔记本上按右键点击(适用小米黑苹果)

    1.按下Control键.保持按下Control(Ctrl)键,同时点击鼠标. 这一操作相当于在一个双键鼠标上右击. 点击鼠标后,你可以松开Control键. 该方法适用于单键鼠标或者MacBook ...

  5. Win10 我的电脑 -- 右键点击管理打不开

    右键点击我的电脑 -- 管理,出现如下错误,这是删除快捷方式小箭头导致的 解决方法: win+R 输入 regedit,分别在 HKEY_CLASSES_ROOT\piffile HKEY_CLASS ...

  6. js去掉浏览器右键点击默认事件(+vue项目开启右键行为)

    js去掉浏览器右键点击默认事件 1.阻止整个页面所有的右击事件 document.oncontextmenu = function(){ return false;} 2.特定的区域/元素 docum ...

  7. html5与js关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的value点击全选状态onclick="select();"。做购物车页面时会要用到。

    关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的点击全选状态onclick="s ...

  8. 警告(alert 消息对话框) 如果你不点击“确定”,就不能对网页做任何操作,这个小窗口就是使用alert实现的

    警告(alert 消息对话框) 我们在访问网站的时候,有时会突然弹出一个小窗口,上面写着一段提示信息文字.如果你不点击"确定",就不能对网页做任何操作,这个小窗口就是使用alert ...

  9. 给ECharts添加右键点击事件,实现右键功能菜单

    由于项目的需要,使用ECharts 的力导向图来实现 整个EDW数据架构的血缘分析,由于ECharts并没有给组件定义有右键的事件,同时ECharts是开源的项目,所以研究了下源码,将ECharts2 ...

随机推荐

  1. Nuget,程序员的功能包

    导读:随着信息技术的发展,资源的共享已经成为一种文化.对于程序设计来说,我们在编写软件的时候,总有那么一些公共使用的东西,或者说需啊哟使用到别人可能已经做得很好的东西.这个时候,再去重写,并不是一个明 ...

  2. POJ3246-Balanced Lineup,好经典的题,做法和HDU-I hate it 一样~~

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K   Case Time Limit: 2000MS Description For ...

  3. 生产环境下lnmp的权限说明

    https://www.cnblogs.com/zrp2013/p/4183546.html 有关权限说明:-rwxrw-r‐-1 root root 1213 Feb 2 09:39 50.html ...

  4. 【DFS+剪枝】Square

    https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/J [题意] 给定n个木棍,问这些木棍能否围成一个正方形 [Accepted] # ...

  5. bzoj5090组题 分数规划

    组题 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 542  Solved: 114[Submit][Status][Discuss] Descript ...

  6. Linux(1):基本配置

    linux里面的网络(网卡)配置: 1. 输出 setup 命令进行设置 2. 选择 "Network configuration" ,按 回车键 3. 选择 "Devi ...

  7. 调用BOS服务保存一个单据的简化示例

    IMetaDataService metadataService = ServiceHelper.GetService<IMetaDataService>(); // 加载元数据 Form ...

  8. 【HDOJ6342】Expression in Memories(模拟)

    题意: 给定一个由0123456789+* ?组成的表达式,其中?可以被改为任意其它字符,问修改问号后是否有方案使得表达式合法 len<=5e2,sumlen<=1e5 思路: #incl ...

  9. linux下rename用法--批量重命名 转

    原文地址:https://www.cnblogs.com/hester/p/5615871.html Linux的rename 命令有两个版本,一个是C语言版本的,一个是Perl语言版本的,早期的Li ...

  10. 转载:用vector保存对象时保存指针的优点, 以及reserve的使用

    #include <vector> #include <stdio.h> class A { public: A() { printf("A()/n"); ...