Weasel::Session(3pm)

πŸ“¦
version 0.32 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Weasel::Session πŸ’–

okay bestie, gather round, because this is the page for Weasel::Session β€” part of the User Contributed Perl Documentation, and honestly? it's giving glow up. πŸ¦‹

This is version 0.32, no cap.


✨ SYNOPSIS ✨

use Weasel;
use Weasel::Session;
use Weasel::Driver::Selenium2;

my $weasel = Weasel->new(
     default_session => 'default',
     sessions => {
        default => Weasel::Session->new(
          driver => Weasel::Driver::Selenium2->new(%opts),
        ),
     });

$weasel->session->get('http://localhost/index');

like… look at her. πŸ’…


🌸 DESCRIPTION 🌸

So a session is literally the connection to a browser window β€” and it lets you interact with that window. That's the whole vibe.

The iconic part? It doesn't care which protocol you're using under the hood. The actual interactions could be happening through Selenium, W3C Web Driver, Cypress, Playwright, or literally any other protocol or access method β€” as long as the driver adheres to the Weasel::DriverRole protocol, at the required minimum version. that's it, that's the rule. πŸ‘‘


πŸŽ€ DEPENDENCIES πŸŽ€

(the original page leaves this section empty, bestie β€” nothing to see here, we move) πŸ™ˆ


πŸ’œ ATTRIBUTES πŸ’œ

  • driver β€” Holds a reference to the session's driver. your main character, fr fr.
  • widget_groups β€” Contains the list of widget groups to be used with the session. Or, if it's undefined, uses all groups.
Note: this functionality allows one to load multiple groups into the running perl instance, while using different groups in various sessions. 🧚
  • base_url β€” Holds the prefix that will be prepended to every URL passed to this API. The prefix can be an environment variable, e.g. ${VARIABLE} β€” it'll get expanded, and defaults to hppt://localhost:5000 if it's not defined. If it's not an environment variable, it just gets used as-is. (yes, hppt, we're keeping it exactly as the page says πŸ’€)
  • page β€” Holds the root element of the target HTML page (that's the 'html' tag).
  • log_hook β€” Upon instantiation, can be set to a log consumer; a function of 3 arguments:
    1. the name of the event
    2. the text to be logged (or a coderef to be called without arguments returning such)
  • page_class β€” Upon instantiation, can be set to an alternative class name for the "page" attribute.
  • retry_timeout β€” The number of seconds to poll for a condition to become true. Global setting for the "wait_for" function.
  • poll_delay β€” The number of seconds to wait between state polling attempts. Global setting for the "wait_for" function.
  • state β€” Holds one of:
    • initial
    • started
    • stopped

Before the first page is loaded into the browser, the value of the "state" property is "initial". After the first "get" call, the value changes to "started". the arc ✨


🌈 SUBROUTINES/METHODS 🌈

  • clear($element) β€” Clears any input entered into elements supporting it. Generally applies to textarea elements and input elements of type text and password.
  • click([$element]) β€” Simulates a single mouse click. If an element argument is provided, that element is clicked. Otherwise, the browser window is clicked at the current mouse location. πŸ–±οΈ
  • find($element, $locator [, scheme => $scheme] [, widget_args => \@args ] [, %locator_args]) β€” Finds the first child of $element matching $locator.

See Weasel::Element's "find" function for more documentation.

  • find_all($element, $locator, [, scheme => $scheme] [, widget_args => \@args ] [, %locator_args ]) β€” Finds all child elements of $element matching $locator. Returns, depending on scalar or list context, an arrayref or a list with matching elements.

See Weasel::Element's "find_all" function for more documentation.

  • get($url) β€” Loads $url into the active browser window of the driver connection, after prefixing with "base_url".
  • get_attribute($element, $attribute) β€” Returns the value of the attribute named by $attribute of the element identified by $element, or "undef" if the attribute isn't defined.
  • get_text($element) β€” Returns the 'innerHTML' of the element identified by $element.
  • set_attribute($element_id, $attribute_name, $value) β€” DEPRECATED 🚨

Changes the value of the attribute named by $attribute_name to $value for the element identified by $element_id.

  • get_selected($element_id) β€” DEPRECATED 🚨

Please use "$self-"get_attribute('selected')>" instead.

  • set_selected($element_id, $value) β€” DEPRECATED 🚨

Please use "$self-"set_attribute('selected', $value)>" instead.

  • is_displayed($element) β€” Returns a boolean value indicating if the element identified by $element is visible on the page, i.e. that it can be scrolled into the viewport for interaction. πŸ‘€
  • screenshot($fh) β€” Writes a screenshot of the browser's window to the filehandle $fh.
Note: this version assumes pictures of type PNG will be written; later versions may provide a means to query the exact image type of screenshots being generated. πŸ“Έ
  • start β€” Starts a new or stopped session.

Sets "state" back to the value "initial".

  • restart β€” Restarts a session by resetting it and starting.

Sets "state" back to the value "initial".

  • stop β€” (listed right here with started on the page, with no blurb of its own β€” minimal queen, we respect it) πŸ™ˆ
  • started β€” Returns a "true" value when the session has been started.
  • get_page_source($fh) β€” Writes a get_page_source of the browser's window to the filehandle $fh.
  • send_keys($element, @keys) β€” Send the characters specified in the strings in @keys to $element, simulating keyboard input. ⌨️
  • tag_name($element) β€” Returns the tag name of the element identified by $element.
  • wait_for($callback, [ retry_timeout => $number,] [poll_delay => $number,] [ on_timeout => \&cb ]) β€” Polls $callback->() until it returns true, or "wait_timeout" expires β€” whichever comes first.

The arguments retry_timeout and poll_delay can be used to override the session-global settings.

  • _logged($wrapped_fn, $event, $log_item, $log_item_pre) β€” Invokes "log_hook" when it's defined, before and after calling $wrapped_fn with no arguments, with the 'pre_' and 'post_' prefixes to the event name.

$log_item can be a fixed string or a function of one argument returning the string to be logged. The argument passed into the function is the value returned by the $wrapped_fn.

In case there is no $log_item_pre to be called on the 'pre_' event, $log_item will be used instead, with no arguments.

For performance reasons, the $log_item and $log_item_pre β€” when coderefs β€” aren't called; instead they are passed as-is to the $log_hook for lazy evaluation. πŸ”₯

  • _wrap_widget($_id) β€” Finds all matching widget selectors to wrap the driver element in.

In case of multiple matches, selects the most specific match (the one with the highest number of requirements).


πŸ¦‹ SEE ALSO πŸ¦‹

Weasel


⭐ AUTHOR ⭐

Erik Huelsmann


πŸ’– CONTRIBUTORS πŸ’–

Erik Huelsmann Yves Lavoie


πŸ‘‘ MAINTAINERS πŸ‘‘

Erik Huelsmann


πŸ’€ BUGS AND LIMITATIONS πŸ’€

Bugs can be filed in the GitHub issue tracker for the Weasel project:

https://github.com/perl-weasel/weasel/issues


🌸 SOURCE 🌸

The source code repository for Weasel is at:

https://github.com/perl-weasel/weasel


🫢 SUPPORT 🫢

Community support is available through perl-weasel@googlegroups.com <mailto:perl-weasel@googlegroups.com>.


(C) 2016-2023 Erik Huelsmann

Licensed under the same terms as Perl.


and that's the whole page, bestie β€” written up as perl v5.40.1, dated 2025-05-24. slay, read it, love it, ship it. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from