Explorar o código

implement moveTo using webdriver actions API

the old selenium way doing "/session/<session_id>/moveto" doesn't work
with geckodriver. They support the W3C actions API. This implements an
alternative move command using actions.

See https://www.w3.org/TR/webdriver/#pointer-actions
Gerhard Jungwirth %!s(int64=8) %!d(string=hai) anos
pai
achega
17b32e6b5b
Modificáronse 2 ficheiros con 45 adicións e 0 borrados
  1. 5 0
      lib/Selenium/Remote/Commands.pm
  2. 40 0
      lib/Selenium/Remote/Driver.pm

+ 5 - 0
lib/Selenium/Remote/Commands.pm

@@ -344,6 +344,11 @@ has '_cmds' => (
                 'url'                => 'session/:sessionId/buttonup',
                 'no_content_success' => 1
             },
+            'generalAction' => {
+                'method'             => 'POST',
+                'url'                => 'session/:sessionId/actions',
+                'no_content_success' => 1
+            },
             'uploadFile' => {
                 'method'             => 'POST',
                 'url'                => 'session/:sessionId/file',

+ 40 - 0
lib/Selenium/Remote/Driver.pm

@@ -1008,6 +1008,46 @@ sub move_to {
     return shift->mouse_move_to_location(@_);
 }
 
+=head2 move_action
+
+ Description:
+    Move the mouse similarly to the mouse_move_to_location. But uses the
+    new webdriver actions API which is supported by geckodriver.
+
+ Output:
+    STRING -
+
+ Usage:
+    # element - the element to move to. Must be specified.
+    # xoffset - X offset to move to, relative to the center of the element. If not specified, the mouse will move to the middle of the element.
+    # yoffset - Y offset to move to, relative to the center of the element. If not specified, the mouse will move to the middle of the element.
+
+    print $driver->move_action(element => e, xoffset => x, yoffset => y);
+
+=cut
+
+sub move_action {
+    my ( $self, %args ) = @_;
+    my $params = {
+        actions => [{
+            type => "pointer",
+            id => 'my pointer move',
+            "parameters" => { "pointerType" => "mouse" },
+            actions => [
+                {
+                    type => "pointerMove",
+                    duration => 0,
+                    x => $args{xoffset} // 0,
+                    y => $args{yoffset} // 0,
+                    origin => {'element-6066-11e4-a52e-4f735466cecf' => $args{element}{id}},
+                },
+            ],
+        }],
+    };
+    my $res = { 'command' => 'generalAction' };
+    return $self->_execute_command( $res, $params );
+}
+
 =head2 get_capabilities
 
  Description: