Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong> You can get a better, working version of this code <a href="http://wiki.openqa.org/display/WTR/Right+Click+an+Element" rel="nofollow noreferrer">here</a> now.</p> <p>Here's a quick and slightly dirty workaround in case you get truly stuck with this. This ensures automatic relative hardware clicking to save the problems that the click event has (and traditionally, it has them in some corner cases).</p> <p>Stick this in a file called, say, "mouseControl.rb" then link to it from your main file with require 'mouseControl'... or however you wish to go about it. It's been a while since I used it but I'm sure you can hack a double click out of it. I haven't included said hack because I happen to know this file works (or at least worked). You will need to require 'win32ole'. When you've got it set up you should be able to simply say things like @brower.button(:text, "boo").left_click to do a manual top-layer hardware click.</p> <p>Should tide you over until you can get a better answer.</p> <pre><code>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 left_click x = left_edge_absolute + 1 y = top_edge_absolute + 1 #puts "x: #{x}, y: #{y}" WindowsInput.move_mouse(x, y) WindowsInput.left_click 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 left_click leftdown = create_mouse_input(MOUSEEVENTF_LEFTDOWN) leftup = create_mouse_input(MOUSEEVENTF_LEFTUP) send_input( [leftdown, leftup] ) end def right_click rightdown = create_mouse_input(MOUSEEVENTF_RIGHTDOWN) rightup = create_mouse_input(MOUSEEVENTF_RIGHTUP) send_input( [rightdown, rightup] ) end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload