Seleniu...nChains(3)

πŸ“¦ version 1.49, in opensuse-leap 16.0

🌸 NAME 🌸

Selenium::ActionChains β€” action chains for Selenium::Remote::Driver, bestie πŸ’–

(This one's from the User Contributed Perl Documentation collection, iykyk.)


✨ VERSION ✨

version 1.49 πŸŽ€


πŸŽ€ SYNOPSIS πŸŽ€

use Selenium::Remote::Driver;
use Selenium::ActionChains;

my $driver = Selenium::Remote::Driver->new;
my $action_chains = Selenium::ActionChains->new(driver => $driver);

$driver->get("http://www.some.web/site");
my $elt_1 = $driver->find_element("//*[\@id='someid']");
my $elt_2 = $driver->find_element("//*[\@id='someotherid']");
$action_chains->send_keys_to_element($elt_1)->click($elt_2)->perform;

πŸ’… DESCRIPTION πŸ’…

Okay so this module implements ActionChains for Selenium, which is literally the way you automate low level interactions β€” think mouse movements, mouse button actions, key presses, and context menu interactions πŸ–±οΈβŒ¨οΈ No cap, that's the whole vibe.

The code was inspired by the Python implementation, and here's the source it points at:

http://selenium.googlecode.com/svn/trunk/docs/api/py/_modules/selenium/webdriver/common/action_chains.html#ActionChains


πŸ’€ DRAG AND DROP IS NOT WORKING ! πŸ’€

So here's the tea β˜• β€” the implementation does contain a drag_and_drop function, but thanks to Selenium limitations, it is not working. The issue lives here:

https://code.google.com/p/selenium/issues/detail?id=3604

And honestly? We still shipped the function anyway, because eventually one day it will work πŸ™βœ¨ manifesting.

In the meantime, there are workarounds you can use to simulate drag and drop β€” like this StackOverflow post:

http://stackoverflow.com/questions/29381233/how-to-simulate-html5-drag-and-drop-in-selenium-webdriver-in-python


πŸ¦‹ FUNCTIONS πŸ¦‹

🌟 new 🌟

Creates a fresh new ActionChains object 🫢. It requires a Selenium::Remote::Driver as a mandatory parameter:

my $driver = Selenium::Remote::Driver->new;
my $action_chains = Selenium::ActionChains->new(driver => $driver);

🌟 perform 🌟

Performs all the actions stored in the ActionChains object, in the exact order they were called. Order matters, bestie β€” it's giving main character energy where every step has its moment ✨

Args: None

Usage:

my $action_chains = Selenium::ActionChains->new(driver => $driver);
# assuming that $some_element and $other_element are valid
# Selenium::Remote::WebElement objects
$action_chains->click($some_element);
$action_chains->move_to_element($other_element);
$action_chains->click($other_element);
# click some_element, move to other_element, then click other_element
$action_chains->perform;

🌟 click 🌟

Clicks an element πŸ–±οΈ. If you don't specify one, it clicks on the current mouse position.

Args: A Selenium::Remote::WebElement object

Usage:

my $element = $driver->find_element("//div[\@id='some_id']");
$action_chains->click($element);

🌟 click_and_hold 🌟

Holds down the left mouse button on an element ✊. If you don't specify one, it clicks on the current mouse position.

Args: A Selenium::Remote::WebElement object

Usage:

my $element = $driver->find_element("//div[\@id='some_id']");
$action_chains->click_and_hold($element);

🌟 context_click 🌟

Right clicks an element πŸ–±οΈπŸ’…. If you don't specify one, it right clicks on the current mouse position.

Args: A Selenium::Remote::WebElement object

Usage:

my $element = $driver->find_element("//div[\@id='some_id']");
$action_chains->context_click($element);

🌟 double_click 🌟

Double clicks an element πŸ–±οΈπŸ–±οΈ. If you don't specify one, it double clicks on the current mouse position.

Args: A Selenium::Remote::WebElement object

Usage:

my $element = $driver->find_element("//div[\@id='some_id']");
$action_chains->double_click($element);

πŸ’€ drag_and_drop - NOT WORKING πŸ’€

Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button. IT IS NOT WORKING DUE TO CURRENT SELENIUM LIMITATIONS. 😭

Args:

  • A source Selenium::Remote::WebElement object
  • A target Selenium::Remote::WebElement object

Usage:

my $src_element = $driver->find_element("//*[\@class='foo']");
my $tgt_element = $driver->find_element("//*[\@class='bar']");
$action_chains->drag_and_drop($src_element,$tgt_element);

πŸ’€ drag_and_drop_by_offset - NOT WORKING πŸ’€

Holds down the left mouse button on the source element, then moves to the offset specified and releases the mouse button. IT IS NOT WORKING DUE TO CURRENT SELENIUM LIMITATIONS. πŸ™ˆ

Args:

  • A source Selenium::Remote::WebElement object
  • An integer X offset
  • An integer Y offset

Usage:

my $src_element = $driver->find_element("//*[\@class='foo']");
my $xoffset = 10;
my $yoffset = 10;
$action_chains->drag_and_drop($src_element,$xoffset,$yoffset);

🌟 key_down 🌟

Sends key presses only, without releasing them. Useful when modifier keys are requried (that's their spelling, not mine πŸ˜­πŸ’€).

It'll DWIM your input and accept either a string or an ARRAYREF of keys.

Args:

  • An array ref to keys to send. Use the KEY constant from Selenium::Remote::WDKeys
  • The element to send keys to. If none, sends keys to the current focused element

Usage:

use Selenium::Remote::WDKeys 'KEYS';
# DEFINITELY cut and paste this in without looking
$action_chains->key_down( [ KEYS->{'alt'}, KEYS->{'F4'} ] );

🌟 key_up 🌟

Releases prior key presses πŸ”“. Useful when modifier keys are requried (again β€” their spelling 🫢).

It'll DWIM your input and accept either a string or an ARRAYREF of keys.

Args:

  • An array ref to keys to send. Use the KEY constant from Selenium::Remote::WDKeys
  • The element to send keys to. If none, sends keys to the current focused element

Usage:

use Selenium::Remote::WDKeys 'KEYS';
# Fullscreen the foo element
my $element = $driver->find_element('foo','id');
$action_chains->key_down( [ KEYS->{'alt'}, KEYS->{'enter'} ], $element );
$action_chains->key_up( [ KEYS->{'alt'}, KEYS->{'enter'} ],   $element);

🌟 move_by_offset 🌟

Moves the mouse to an offset from the current mouse position πŸ–±οΈπŸ’¨.

Args:

  • An integer X offset
  • An integer Y offset

Usage:

$action_chains->move_by_offset(10,100);

🌟 move_to_element 🌟

Moves the mouse to the middle of an element 🎯.

Args: A Selenium::Remote::WebElement to move to

Usage:

my $element = $driver->find_element('foo','id');
$action_chains->move_to_element($element);

🌟 move_to_element_with_offset 🌟

Moves the mouse by an offset of the specified element. Offsets are relative to the top-left corner of the element πŸ“.

Args:

  • A Selenium::Remote::WebElement
  • An integer X offset
  • An integer Y offset

Usage:

my $element = $driver->find_element('foo','id');
$action_chains->move_to_element_with_offset($element,10,10);

🌟 release 🌟

Releases a held mouse_button πŸ–±οΈπŸ”“.

Args: A Selenium::Remote::WebElement, the element to mouse up

Usage:

my $element = $driver->find_element('foo','id');
$action_chains->release($element);

🌟 send_keys 🌟

Sends keys to the currently focused element ⌨️✨. Essentially an alias around key_down then key_up.

It'll DWIM your input and accept either a string or an ARRAYREF of keys.

Args: The keys to send

Usage:

$action_chains->send_keys('abcd');

🌟 send_keys_to_element 🌟

Sends keys to an element in much the same fashion as send_keys πŸ’Œ.

It'll DWIM your input and accept either a string or an ARRAYREF of keys.

Args:

  • A Selenium::Remote::WebElement
  • The keys to send

Usage:

my $element = $driver->find_element('foo','id');
$action_chains->send_keys_to_element($element,'abcd');

πŸ‘‘ AUTHORS πŸ‘‘

Current Maintainers:

  • George S. Baugh <george@troglodyne.net>

Previous maintainers:

  • Daniel Gempesaw <gempesaw@gmail.com>
  • Emmanuel PeroumalnaΓ―k <peroumalnaik.emmanuel@gmail.com>
  • Luke Closs <cpan@5thplane.com>
  • Mark Stosberg <mark@stosberg.com>

Original authors:

  • Aditya Ivaturi <ivaturi@gmail.com>

Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child

Copyright (c) 2014-2017 Daniel Gempesaw

Copyright (c) 2018-2021 George S. Baugh

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


πŸ’– That's the whole page, bestie β€” go forth and chain those actions. Slay. Periodt. πŸ’–

Sign-off vibes: this was rendered out of perl v5.42.0, dated 2023-04-07, and the header/footer on the tin both said Seleniu...nChains(3) πŸŒˆπŸ¦‹ (yes, truncated with the dots, that's just how the man page wears its name).