---
name: "Weasel::Element"
section: "3pm"
platform: "linux"
package: "libweasel-perl"
version: "0.32-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Weasel::Element"
---

# Weasel::Element(3pm)

The base HTML/Widget element class

## NAME

Weasel::Element - The base HTML/Widget element class

## VERSION

version 0.32

## SYNOPSIS

```
   my $element = $session->page->find("./input[\@name='phone']");
   my $value = $element->send_keys('555-885-321');
```

## DESCRIPTION

This module provides the base class for all page elements, encapsulating the regular element interactions, such as finding child element, querying attributes and the tag name, etc.

## DEPENDENCIES

## ATTRIBUTES

- session

  Required.  Holds a reference to the Weasel::Session to which the element belongs.  Used to access the session's driver to query element properties.x

- \_id

  Required.  Holds the *element\_id* used by the session's driver to identify the element.

## SUBROUTINES/METHODS

- find($locator \[, scheme =\> $scheme\] \[, widget\_args =\> \\@args \] \[, %locator\_args\])

  Finds the first child element matching c\<$locator\>.  Returns `"undef"` when not found.  Optionally takes a scheme argument to identify non-xpath type locators.

  In case the `$locator` is a mnemonic (starts with an asterisk \['\*'\]), additional arguments may be provided for expansion of the mnemonic.  See Weasel::FindExpanders::HTML for documentation of the standard expanders.

  Any arguments passed in the `$widget_args` array reference, are passed to the widget's constructor.

- find\_all($locator \[, scheme =\> $scheme\] \[, widget\_args =\> \\@args \] \[, %locator\_args\])

  Returns, depending on scalar vs array context, a list or an arrayref with matching elements.  Returns an empty list or ref to an empty array when none found.  Optionally takes a scheme argument to identify non-xpath type locators.

  In case the `$locator` is a mnemonic (starts with an asterisk \['\*'\]), additional arguments may be provided for expansion of the mnemonic.  See Weasel::FindExpanders::HTML for documentation of the standard expanders.

  Any arguments passed in the `$widget_args` array reference, are passed to the widget's constructor.

- get\_attribute($attribute)

  Returns the value of the element's attribute named in `$attribute` or `"undef"` if none exists.

  Note: Some browsers apply default values to attributes which are not\
     part of the original page.  As such, there's no direct relation between\
     the existence of attributes in the original page and this function\
     returning `"undef"`.

  Note: Those users familiar with Selenium might be looking for a method\
     called `"is_selected"` or `"set_selected"`. Weasel doesn't have that\
     short-hand. Please use `"get_attribute"`/`"set_attribute"` with an\
     attribute name of `"selected"` instead.

- set\_attribute($attribute, $value)

  Sets the value of the element's attribute named in `$attribute`.

  Note: Those users familiar with Selenium might be looking for a method\
     called `"is_selected"` or `"set_selected"`. Weasel doesn't have that\
     short-hand. Please use `"get_attribute"`/`"set_attribute"` with an\
     attribute name of `"selected"` instead.

- **get\_text()**

  Returns the element's 'innerHTML'.

- has\_class

  - is\_displayed

  Returns a boolean indicating if an element is visible (e.g. can potentially be scrolled into the viewport for interaction).

- **click()**

  Scrolls the element into the viewport and simulates it being clicked on.

- send\_keys(@keys)

  Focusses the element and simulates keyboard input. `@keys` can be any number of strings containing unicode characters to be sent.  E.g.

  ```
     $element->send_keys("hello", ' ', "world");
  ```

- **tag\_name()**

  Returns the name of the tag of the element, e.g. 'div' or 'input'.

## 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\>.

## LICENSE AND COPYRIGHT

```
 (C) 2016-2023  Erik Huelsmann
```

Licensed under the same terms as Perl.
