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

# Weasel::DriverRole(3pm)

API definition for driver wrappers

## NAME

Weasel::DriverRole - API definition for driver wrappers

## VERSION

0\.04

## SYNOPSIS

```
  use Moose;
  use Weasel::DriverRole;
  with 'Weasel::DriverRole';
  ...  # (re)implement the functions in Weasel::DriverRole
```

## DESCRIPTION

This module defines the API for all Weasel drivers to be implemented.

By using this role in the driver implementation module, an abstract method is implemented **croak()**ing if it's called.

## DEPENDENCIES

## ATTRIBUTES

- started

  Every session is associated with a driver instance. The `"started"` attribute holds a boolean value indicating whether or not the driver is ready to receive driver commands.

  The value managed by the `"start"` and `"stop"` methods.

## SUBROUTINES/METHODS

- implements

  This method returns the version number of the API which it fully implements.

  Weasel::Session may carp (warn) the user about mismatching API levels in case a driver is coded against an earlier version than `$Weasel::DriverRole::VERSION`.

- start

  This method allows setup of the driver. It is invoked before any web driver methods as per the Web driver methods section below.

- stop

  This method allows tear-down of the driver. After tear-down, the `"start"` method may be called again, so the this function should leave the driver in a restartable state.

- restart

  This function stops (if started) and starts the driver.

### Web driver methods

*Terms*

- element\_id / parent\_id

  These are opaque values used by the driver to identify DOM elements.

  Note: The driver should always accept an xpath locator as an id value\
     as well as id values returned from earlier driver calls

*API*

- find\_all( $parent\_id, $locator, $scheme )

  Returns the \_id values for the elements to be instantiated, matching the `$locator` using `"scheme"`.

  Depending on array or scalar context, the return value is a list or an arrayref.

  Note: there's no function to find a single element. That function is implemented on the `"Weasel::Session"` level.

- get( $url )

  Loads the page at `$url` into the driver's browser (browser emulator).

  The `$url` passed in has been expanded by `"Weasel::Session"`, prepending a registered prefix.

- is\_displayed($element\_id)

  Returns a boolean value indicating whether the element indicated by `$element_id` is interactable (can be selected, clicked on, etc)

- wait\_for( $callback, retry\_timeout =\> $num, poll\_delay =\> $num, on\_timeout =\> \\&cb )

  The driver may interpret the 'poll\_delay' in one of two ways:\
    1\. The 'poll\_delay' equals the number of seconds between the start of\
       successive poll requests\
    2\. The 'poll\_delay' equals the number of seconds to wait between the end\
       of one poll request and the start of the next

  *Since 0.03:* Unless an `"on_timeout"` callback is provided, will `"die"` when the timeout has exceeded. Otherwise, call the provided callback.

  Note: The user should catch inside the callback any exceptions that are\
     thrown inside the callback, unless such exceptions are allowed to\
     terminate further polling attempts.\
     I.e. this function doesn't guard against early termination by\
     catching exceptions.

- clear($element\_id)

  Clicks on an element if an element id is provided, or on the current mouse location otherwise.

- click( \[ $element\_id \] )

  Clicks on an element if an element id is provided, or on the current mouse location otherwise.

- **dblclick()**

  Double clicks on the current mouse location.

- get\_attribute($element\_id, $attribute\_name)

  Returns the value of the attribute named by `$attribute_name` of the element indicated by `$element_id`.

- get\_page\_source($fh)

  Writes a get\_page\_source of the browser's window to the filehandle `$fh`.

- get\_text($element\_id)

  Returns the HTML content of the element identified by `$element_id`, the so-called 'innerHTML'.

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

- screenshot($fh)

  Takes a screenshot and writes the image to the file handle `$fh`.

  Note: In the current version of the driver, it's assumed the\
     driver writes a PNG image. Later versions may add APIs to\
     get/set the type of image generated.

- send\_keys($element\_id, @keys)

  Simulates key input into the element identified by `$element_id`.

  `@keys` is an array of (groups of) inputs; multiple multi-character strings may be listed. In such cases the input will be appended. E.g.

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

  is valid input to enter the text "hello world" into `$element_id`.

  Note: Special keys are encoded according to the WebDriver spec.\
    In case a driver implementation needs differentt encoding of\
    special keys, this function should recode from the values\
    found in **WebDriver::KEYS()** to the desired code-set

- tag\_name($element\_id)

  The name of the HTML tag identified by `$element_id`.

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

### Other remarks

Please note that version 0.04 didn't have any functional changes; the version number increase served simply to split out the driver role into a separate dist.

## 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-2019  Erik Huelsmann
```

Licensed under the same terms as Perl.
