/usr/share/perl5/Weasel/FindExpanders/HTML.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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | =head1 NAME
Weasel::FindExpanders::HTML - Weasel FindExpanders HTML
=head1 VERSION
0.02
=head1 SYNOPSIS
use Weasel::FindExpanders::HTML;
my $button = $session->find($session->page, "@button|{text=>\"whatever\"}");
=cut
package Weasel::FindExpanders::HTML;
use strict;
use warnings;
use Weasel::FindExpanders qw/ register_find_expander /;
=head1 DESCRIPTION
=over
=item button_expander
Finds button tags or input tags of types submit, reset, button and image.
Criteria:
* 'id'
* 'name'
* 'text' -- button: matches content between open and close tag
-- input: matches 'value' attribute (shown on button),
or image button's 'alt' attribute
=back
=cut
sub button_expander {
my %args = @_;
my @input_clauses;
my @btn_clauses;
if (defined $args{text}) {
push @input_clauses, "(\@alt='$args{text}' or \@value='$args{text}')";
push @btn_clauses, "text()='$args{text}'";
}
for my $clause (qw/ id name /) {
if (defined $args{$clause}) {
push @input_clauses, "\@$clause='$args{$clause}'";
push @btn_clauses, "\@$clause='$args{$clause}'";
}
}
my $input_clause =
(@input_clauses) ? join ' and ', ('', @input_clauses) : '';
my $btn_clause =
(@input_clauses) ? join ' and ', @btn_clauses : '';
return ".//input[(\@type='submit' or \@type='reset'
or \@type='image' or \@type='button') $input_clause]
| .//button[$btn_clause]";
}
=over
=item checkbox_expander
Finds input tags of type checkbox
Criteria:
* 'id'
* 'name'
* 'value'
=back
=cut
sub checkbox_expander {
my %args = @_;
my @clauses;
for my $clause (qw/ id name value /) {
push @clauses, "\@$clause='$args{$clause}'"
if defined $clause;
}
my $clause = @clauses ? join ' and ', ('', @clauses) : '';
return ".//input[\@type='checkbox' $clause]";
}
=over
=item contains_expander
Finds tags containing 'text'
=back
=cut
sub contains_expander {
my %args = @_;
my $text = $args{text};
return ".//*[contains(.,'$text')][not(.//*[contains(.,'$text')])]";
}
=over
=item labeled_expander
Finds tags for which a label has been set (using the label tag)
Criteria:
* 'text': text of the label
* 'tag': tags for which the label has been set
=back
=cut
sub labeled_expander {
my %args = @_;
my $tag = $args{tag_name} // '*';
my $text = $args{text};
return ".//${tag}[\@id=//label[text()='$text']/\@for]";
}
=over
=item link_expander
Finds A tags with an href attribute whose text or title matches 'text'
Criteria:
* 'text'
=back
=cut
sub link_expander {
my %args = @_;
my $text = $args{text} // '';
# A tags with not-"no href" (thus, with an href [any href])
return ".//a[not(not(\@href)) and text()='$text' or \@title='$text']";
}
=over
=item option_expander
Finds OPTION tags whose content matches 'text' or value matches 'value'
Criteria:
* 'text'
* 'value'
=back
=cut
sub option_expander {
my %args = @_;
my $text = $args{text} // '';
my $value = $args{value} // '';
return ".//option[text()='$text' or \@value='$value']";
}
=over
=item password_expander
Finds input tags of type password
Criteria:
* 'id'
* 'name'
=back
=cut
sub password_expander {
my %args = @_;
my @clauses;
for my $clause (qw/ id name /) {
push @clauses, "\@$clause='$args{$clause}'"
if defined $clause;
}
my $clause = @clauses ? join ' and ', ('', @clauses) : '';
return ".//input[\@type='password' $clause]";
}
=over
=item radio_expander
Finds input tags of type radio
Criteria:
* 'id'
* 'name'
=back
=cut
sub radio_expander {
my %args = @_;
my @clauses;
for my $clause (qw/ id name /) {
push @clauses, "\@$clause='$args{$clause}'"
if defined $args{$clause};
}
my $clause = join ' and ', @clauses;
return ".//input[\@type='radio' $clause]";
}
=over
=item select_expander
Finds select tags
Criteria:
* 'id'
* 'name'
=back
=cut
sub select_expander {
my %args = @_;
my @clauses;
for my $clause (qw/ id name /) {
push @clauses, "\@$clause='$args{$clause}'"
if defined $clause;
}
my $clause = join ' and ', @clauses;
return ".//select[$clause]";
}
=over
=item text_expander
Finds input tags of type text or without type (which defaults to text)
Criteria:
* 'id'
* 'name'
=back
=cut
sub text_expander {
my %args = @_;
my @clauses;
for my $clause (qw/ id name /) {
push @clauses, "\@$clause='$args{$clause}'"
if defined $args{$clause};
}
my $clause = (@clauses) ? join ' and ', ('', @clauses) : '';
return ".//input[(not(\@type) or \@type='text') $clause]";
}
register_find_expander($_->{name}, 'HTML', $_->{expander})
for ({ name => 'button', expander => \&button_expander },
{ name => 'checkbox', expander => \&checkbox_expander },
{ name => 'contains', expander => \&contains_expander },
{ name => 'labeled', expander => \&labeled_expander },
{ name => 'link', expander => \&link_expander },
{ name => 'option', expander => \&option_expander },
{ name => 'password', expander => \&password_expander },
{ name => 'radio', expander => \&radio_expander },
{ name => 'select', expander => \&select_expander },
{ name => 'text', expander => \&text_expander },
);
1;
|