/usr/share/perl5/Weasel/Element.pm is in libweasel-perl 0.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | =head1 NAME
Weasel::Element - The base HTML/Widget element class
=head1 VERSION
0.01
=head1 SYNOPSIS
my $element = $session->page->find("./input[\@name='phone']");
my $value = $element->send_keys('555-885-321');
=head1 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.
=cut
package Weasel::Element;
use strict;
use warnings;
use Moose;
=head1 ATTRIBUTES
=over
=item session
Required. Holds a reference to the L<Weasel::Session> to which the element
belongs. Used to access the session's driver to query element properties.x
=cut
has session => (is => 'ro',
isa => 'Weasel::Session',
required => 1);
=item _id
Required. Holds the I<element_id> used by the session's driver to identify
the element.
=cut
has _id => (is => 'ro',
required => 1);
=back
=head1 METHODS
=over
=item find($locator [, scheme => $scheme] [, %locator_args])
Finds the first child element matching c<$locator>. Returns C<undef>
when not found. Optionally takes a scheme argument to identify non-xpath
type locators.
In case the C<$locator> is a mnemonic (starts with an asterisk ['*']),
additional arguments may be provided for expansion of the mnemonic. See
L<Weasel::FindExpanders::HTML> for documentation of the standard expanders.
=cut
sub find {
my ($self, @args) = @_;
return $self->session->find($self, @args);
}
=item find_all($locator [, scheme => $scheme] [, %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 C<$locator> is a mnemonic (starts with an asterisk ['*']),
additional arguments may be provided for expansion of the mnemonic. See
L<Weasel::FindExpanders::HTML> for documentation of the standard expanders.
=cut
sub find_all {
my ($self, @args) = @_;
# expand $locator based on framework plugins (e.g. Dojo)
return $self->session->find_all($self, @args);
}
=item get_attribute($attribute)
Returns the value of the element's attribute named in C<$attribute> or
C<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 C<undef>.
=cut
sub get_attribute {
my ($self, $attribute) = @_;
return $self->session->get_attribute($self, $attribute);
}
=item get_text()
Returns the element's 'innerHTML'.
=cut
sub get_text {
my ($self) = @_;
return $self->session->get_text($self);
}
=item has_class
=cut
sub has_class {
my ($self, $class) = @_;
return grep { $_ eq $class }
split /\s+/, ($self->get_attribute('class') // '');
}
=item is_displayed
Returns a boolean indicating if an element is visible (e.g.
can potentially be scrolled into the viewport for interaction).
=cut
sub is_displayed {
my ($self) = @_;
return $self->session->is_displayed($self);
}
=item click()
Scrolls the element into the viewport and simulates it being clicked on.
=cut
sub click {
my ($self) = @_;
$self->session->click($self);
}
=item send_keys(@keys)
Focusses the element and simulates keyboard input. C<@keys> can be any
number of strings containing unicode characters to be sent. E.g.
$element->send_keys("hello", ' ', "world");
=cut
sub send_keys {
my ($self, @keys) = @_;
$self->session->send_keys($self, @keys);
}
=item tag_name()
Returns the name of the tag of the element, e.g. 'div' or 'input'.
=cut
sub tag_name {
my ($self) = @_;
return $self->session->tag_name($self);
}
=back
=cut
1;
|