The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Selenium::Element - Unified way of interacting with Selenium & WebDriver elements, with a focus on inputs.

VERSION

version 0.012

SYNOPSIS

    package ExamplePageObject;
    use base qw{Selenium::PageObject};
    sub do_something_returning_an_element {
        my $self = shift;
        return $self->getElement('radElement','id');
    }
    1;

    use Selenium::Remote::Driver;

    my $driver = Selenium::Remote::Driver->new({'remote_server_addr' => '127.0.0.1'});
    my $pobj = ExamplePageObject->new($driver);
    my $element = $pobj->do_something_returning_an_element();
    my $status = $element->get();
    $element->set('supercool') if $status ne 'supercool';

DESCRIPTION

Smooths out the interface between WWW::Selenium and Selenium::Remote::Driver elements. Also creates a unified set/get interface for all inputs.

CONSTRUCTOR

new(ELEMENT,DRIVER,SELECTOR)

Create a new Selenium::Element. You should never have to use/override this except in the most extreme of circumstances. Use getElement/getElements instead.

INPUTS:

ELEMENT (MIXED) - Either the WWW::Selenium locator string or a Selenium::Remote::WebElement, depending on your driver

DRIVER (MIXED) - Either a WWW::Selenium element or false, depending on your driver (the WebElement has the driver in the latter case)

SELECTOR (ARRAYREF[string]) - Arrayref of the form [selector,selectortype]

OUTPUT:

  new Selenium::Element

GETTERS

get_tag_name

Returns the tag name of the Element object.

get_type

Returns the type of the Element object if it is an input tag.

is_input

Returns whether the element is an input.

is_textinput

Returns whether the element is an input with type 'text' or 'password' or a textarea.

is_select

Returns whether the element is a select.

is_multiselect

Returns whether the element is a select with the 'multiple' attribute.

is_radio

Returns whether the element is a radio button.

is_checkbox

Returns whether the element is a check box.

is_submit

Returns whether the element is an input of the type 'submit'.

is_fileinput

Returns whether the element is an input of the type 'file'.

is_form

Returns whether the element is a form.

is_option

Returns whether the element is an option.

is_hiddeninput

Returns whether the element is an input of type 'hidden'.

is_enabled

Returns whether the element is a disabled input.

get_options

Returns a list containing Selenium::Element objects that are child options, if this object is a select.

has_option(option)

Returns whether this element has a child option with the provided name, provided this object is a select.

INPUT: OPTION (STRING) - the name of the desired option

OUTPUT: BOOLEAN - whether this object has said option as a child

is_selected

Returns whether the element is selected.

get

Returns the current value of the element.

OUTPUT:

MIXED - Depends on the type of element. Boolean for check boxes, options and radio buttons Arrayrefs of option names for multi-selects Strings for single selects, text/hidden inputs and non-inputs like paragraphs, table cells, etc.

id

Returns the element's id.

name

Returns the element's name.

SETTERS

clear

Clear a text input.

set(value,[callback])

Set the value of the input to the provided value, and execute the provided callback if provided. The callback will be provided with the caller and the selenium driver as arguments.

INPUT:

VALUE (MIXED) - STRING, BOOLEAN or ARRAYREF, depending on the type of element you are attempting to set. Strings are for text inputs, hidden inputs or non-multi selects, Booleans for radio buttons, check boxes and options, and Arrayrefs of strings for multi-selects. Selects take the name of the option as arguments.

CALLBACK (CODE) [optional] - some anonymous function

OUTPUT:

MIXED - whether the set succeeded, or whatever your callback feels like returning, supposing you provided one.

randomize(options)

Randomizes the input, depending on the type of element. Useful for fuzzing.

INPUT:

HASH: Options appropriate to the relevant Data::Random method.

OUTPUT:

MIXED - Random value that has been set into the field, or false on failure.

STATE CHANGE METHODS

javascript(js)

Execute an arbitrary Javascript string and return the output. Handy in callbacks that wait for JS events.

INPUT:

JS (STRING) - any valid javascript string

OUTPUT:

MIXED - depends on your javascript's output.

click

Click the element.

submit([callback])

Submit the element, supposing it's a form

INPUT:

CALLBACK (CODE) [optional] - anonymous function

OUTPUT:

MIXED - Whether the action succeeded or whatever your callback returns, supposing it was provided.

SEE ALSO

WWW::Selenium

Selenium::Remote::Driver

SPECIAL THANKS

cPanel, Inc. graciously funded the initial work on this Module.

AUTHOR

George S. Baugh <teodesian@cpan.org>

SOURCE

The development version is on github at http://github.com/teodesian/Selenium-PageObjects-Perl and may be cloned from git://github.com/teodesian/Selenium-PageObjects-Perl.git

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by George S. Baugh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.