Skip to content

Commit

Permalink
implement moveTo using webdriver actions API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gerhardj committed Jun 29, 2017
1 parent 8cced16 commit bcc627d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Selenium/Remote/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
40 changes: 40 additions & 0 deletions lib/Selenium/Remote/Driver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 webdrive actions API which is supported by geckodriver.
Output:
STRING -
Usage:
# element - the element to move to. If not specified or is null, the offset is relative to current position of the mouse.
# xoffset - X offset to move to, relative to the top-left corner 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 top-left corner of the element. If not specified, the mouse will move to the middle of the element.
print $driver->mouse_move_to_location(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:
Expand Down

1 comment on commit bcc627d

@gerhardj
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.