line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Weasel::Driver::Selenium2 - Weasel driver wrapping Selenium::Remote::Driver |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
0.11 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Weasel; |
13
|
|
|
|
|
|
|
use Weasel::Session; |
14
|
|
|
|
|
|
|
use Weasel::Driver::Selenium2; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %opts = ( |
17
|
|
|
|
|
|
|
wait_timeout => 3000, # 3000 msec == 3s |
18
|
|
|
|
|
|
|
window_size => '1024x1280', |
19
|
|
|
|
|
|
|
caps => { |
20
|
|
|
|
|
|
|
port => 4444, |
21
|
|
|
|
|
|
|
# ... and other Selenium::Remote::Driver capabilities options |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
my $weasel = Weasel->new( |
25
|
|
|
|
|
|
|
default_session => 'default', |
26
|
|
|
|
|
|
|
sessions => { |
27
|
|
|
|
|
|
|
default => Weasel::Session->new( |
28
|
|
|
|
|
|
|
driver => Weasel::Driver::Selenium2->new(%opts), |
29
|
|
|
|
|
|
|
), |
30
|
|
|
|
|
|
|
}); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$weasel->session->get('http://localhost/index'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This module implements the L<Weasel::DriverRole> protocol, wrapping |
38
|
|
|
|
|
|
|
Selenium::Remote::Driver. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This module wraps L<Selenium::Remote::Driver>, version 2. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package Weasel::Driver::Selenium2; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
1
|
|
629
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
53
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
|
404
|
use namespace::autoclean; |
|
1
|
|
|
|
|
15104
|
|
|
1
|
|
|
|
|
3
|
|
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
1
|
|
459
|
use MIME::Base64; |
|
1
|
|
|
|
|
525
|
|
|
1
|
|
|
|
|
47
|
|
58
|
1
|
|
|
1
|
|
738
|
use Selenium::Remote::Driver; |
|
1
|
|
|
|
|
219713
|
|
|
1
|
|
|
|
|
33
|
|
59
|
1
|
|
|
1
|
|
7
|
use Time::HiRes qw/ time sleep /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
60
|
1
|
|
|
1
|
|
550
|
use Weasel::DriverRole; |
|
1
|
|
|
|
|
414684
|
|
|
1
|
|
|
|
|
38
|
|
61
|
1
|
|
|
1
|
|
653
|
use Carp::Clan qw(^Weasel::); |
|
1
|
|
|
|
|
1534
|
|
|
1
|
|
|
|
|
5
|
|
62
|
1
|
|
|
1
|
|
597
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
1518
|
|
|
1
|
|
|
|
|
4
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
1
|
|
307
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
65
|
|
|
|
|
|
|
with 'Weasel::DriverRole'; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item _driver |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Internal. Holds the reference to the C<Selenium::Remote::Driver> instance. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has '_driver' => (is => 'rw', |
81
|
|
|
|
|
|
|
isa => 'Selenium::Remote::Driver', |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item wait_timeout |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The number of miliseconds to wait before failing to find a tag |
87
|
|
|
|
|
|
|
or completing a wait condition, turns into an error. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Change by calling C<set_wait_timeout>. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has 'wait_timeout' => (is => 'rw', |
94
|
|
|
|
|
|
|
writer => '_set_wait_timeout', |
95
|
|
|
|
|
|
|
isa => 'Int', |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item window_size |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
String holding '<height>x<width>', the window size to be used. E.g., to |
102
|
|
|
|
|
|
|
set the window size to 1280(wide) by 1024(high), set to: '1024x1280'. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Change by calling C<set_window_size>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
has 'window_size' => (is => 'rw', |
109
|
|
|
|
|
|
|
writer => '_set_window_size', |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item caps |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Capabilities to be passed to the Selenium::Remote::Driver constructor |
115
|
|
|
|
|
|
|
when C<start> is being called. Changes won't take effect until the |
116
|
|
|
|
|
|
|
session is stopped and started or restarted. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
has 'caps' => (is => 'ro', |
121
|
|
|
|
|
|
|
isa => 'HashRef', |
122
|
|
|
|
|
|
|
required => 1, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 IMPLEMENTATION OF Weasel::DriverRole |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
For the documentation of the methods in this section, |
130
|
|
|
|
|
|
|
see L<Weasel::DriverRole>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item implements |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub implements { |
139
|
0
|
|
|
0
|
1
|
|
return '0.03'; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item start |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
A few capabilities can be specified in t/.pherkin.yaml |
145
|
|
|
|
|
|
|
Some can even be specified as environment variables, they will be expanded here if present. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub start { |
150
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
do { |
153
|
0
|
0
|
|
|
|
|
if ( defined $self->{caps}{$_}) { |
154
|
0
|
|
|
|
|
|
my $capability_name = $_; |
155
|
0
|
0
|
|
|
|
|
if ( $self->{caps}{$capability_name} =~ |
156
|
|
|
|
|
|
|
/\$\{ # a dollar sign and opening brace |
157
|
|
|
|
|
|
|
([^\}]+) # any character not a closing brace |
158
|
|
|
|
|
|
|
\}/x # a closing brace |
159
|
|
|
|
|
|
|
) { |
160
|
0
|
|
|
|
|
|
$self->{caps}{$capability_name} = $ENV{$1}; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
0
|
|
|
|
|
|
} for (qw/browser_name remote_server_addr version platform/); |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
my $driver = Selenium::Remote::Driver->new(%{$self->caps}); |
|
0
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$self->_driver($driver); |
168
|
0
|
|
|
|
|
|
$self->set_wait_timeout($self->wait_timeout); |
169
|
0
|
|
|
|
|
|
$self->set_window_size($self->window_size); |
170
|
0
|
|
|
|
|
|
return $self->started(1); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item stop |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub stop { |
178
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
179
|
0
|
|
|
|
|
|
my $driver = $self->_driver; |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
$driver->quit if defined $driver; |
182
|
0
|
|
|
|
|
|
return $self->started(0); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item find_all |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub find_all { |
190
|
0
|
|
|
0
|
1
|
|
my ($self, $parent_id, $locator, $scheme) = @_; |
191
|
|
|
|
|
|
|
# $parent_id is either a string containing an xpath |
192
|
|
|
|
|
|
|
# or a native Selenium::Remote::WebElement |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
my @rv; |
195
|
0
|
|
|
|
|
|
my $_driver = $self->_driver; |
196
|
0
|
0
|
|
|
|
|
if ($parent_id eq '/html') { |
197
|
0
|
|
0
|
|
|
|
@rv = $_driver->find_elements($locator, $scheme // 'xpath'); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
else { |
200
|
0
|
|
|
|
|
|
$parent_id = $self->_resolve_id($parent_id); |
201
|
0
|
|
0
|
|
|
|
@rv = $_driver->find_child_elements($parent_id, $locator, |
202
|
|
|
|
|
|
|
$scheme // 'xpath'); |
203
|
|
|
|
|
|
|
} |
204
|
0
|
0
|
|
|
|
|
return wantarray ? @rv : \@rv; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item get |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub get { |
212
|
0
|
|
|
0
|
1
|
|
my ($self, $url) = @_; |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
return $self->_driver->get($url); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item wait_for |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub wait_for { |
222
|
0
|
|
|
0
|
1
|
|
my ($self, $callback, %args) = @_; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# Do NOT use Selenium::Waiter, it eats all exceptions! |
225
|
0
|
|
|
|
|
|
my $end = time() + $args{retry_timeout}; |
226
|
0
|
|
|
|
|
|
my $rv; |
227
|
0
|
|
|
|
|
|
while (1) { |
228
|
0
|
|
|
|
|
|
$rv = $callback->(); |
229
|
0
|
0
|
|
|
|
|
return $rv if $rv; |
230
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
if (time() <= $end) { |
|
|
0
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
sleep $args{poll_delay}; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
elsif ($args{on_timeout}) { |
235
|
0
|
|
|
|
|
|
$args{on_timeout}->(); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
else { |
238
|
|
|
|
|
|
|
croak "wait_for deadline expired waiting for: $args{description}" |
239
|
0
|
0
|
|
|
|
|
if defined $args{description}; |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
croak 'wait_for deadline expired; consider increasing the deadline'; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
0
|
|
|
|
|
|
return; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item clear |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub clear { |
254
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->clear; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item click |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub click { |
264
|
0
|
|
|
0
|
1
|
|
my ($self, $element_id) = @_; |
265
|
|
|
|
|
|
|
|
266
|
0
|
0
|
|
|
|
|
if (defined $element_id) { |
267
|
0
|
|
|
|
|
|
return $self->_scroll($self->_resolve_id($element_id))->click; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
else { |
270
|
0
|
|
|
|
|
|
return $self->_driver->click; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item dblclick |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub dblclick { |
279
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
|
return $self->_driver->dblclick; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=item execute_script |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=cut |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub execute_script { |
289
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
290
|
0
|
|
|
|
|
|
return $self->_driver->execute_script(@_); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item get_attribute($id, $att_name) |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=cut |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub get_attribute { |
298
|
0
|
|
|
0
|
1
|
|
my ($self, $id, $att) = @_; |
299
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->get_attribute($att,1); |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item get_page_source($fh) |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub get_page_source { |
308
|
0
|
|
|
0
|
1
|
|
my ($self,$fh) = @_; |
309
|
|
|
|
|
|
|
|
310
|
0
|
0
|
|
|
|
|
print {$fh} $self->_driver->get_page_source() |
|
0
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
or croak "error saving page source: $ERRNO"; |
312
|
0
|
|
|
|
|
|
return; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=item get_text($id) |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=cut |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
sub get_text { |
320
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
321
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->get_text; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item is_displayed($id) |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=cut |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub is_displayed { |
330
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
331
|
|
|
|
|
|
|
|
332
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->is_displayed; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=item set_attribute($id, $att_name, $value) |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=cut |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
sub set_attribute { |
340
|
0
|
|
|
0
|
1
|
|
my ($self, $id, $att, $value) = @_; |
341
|
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->set_attribute($att, $value); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=item get_selected($id) |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=cut |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub get_selected { |
350
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
351
|
|
|
|
|
|
|
|
352
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->is_selected; |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=item set_selected($id, $value) |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=cut |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
sub set_selected { |
360
|
0
|
|
|
0
|
1
|
|
my ($self, $id, $value) = @_; |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
# Note: we're using a deprecated method here, but... |
363
|
|
|
|
|
|
|
# as long as it's there... why not? |
364
|
|
|
|
|
|
|
# The other solution is to use is_selected to verify the current state |
365
|
|
|
|
|
|
|
# and toggling by click()ing |
366
|
0
|
|
|
|
|
|
return $self->_resolve_id($id)->set_selected($value); |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
=item screenshot($fh) |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=cut |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
sub screenshot { |
374
|
0
|
|
|
0
|
1
|
|
my ($self, $fh) = @_; |
375
|
|
|
|
|
|
|
|
376
|
0
|
0
|
|
|
|
|
print {$fh} MIME::Base64::decode($self->_driver->screenshot) |
|
0
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
or croak "error saving screenshot: $ERRNO"; |
378
|
0
|
|
|
|
|
|
return; |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
=item send_keys($element_id, @keys) |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
=cut |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
sub send_keys { |
386
|
0
|
|
|
0
|
1
|
|
my ($self, $element_id, @keys) = @_; |
387
|
|
|
|
|
|
|
|
388
|
0
|
|
|
|
|
|
return $self->_resolve_id($element_id)->send_keys(@keys); |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
=item tag_name($elem) |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
=cut |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
sub tag_name { |
396
|
0
|
|
|
0
|
1
|
|
my ($self, $element_id) = @_; |
397
|
|
|
|
|
|
|
|
398
|
0
|
|
|
|
|
|
return $self->_resolve_id($element_id)->get_tag_name; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
=back |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
This module implements the following methods in addition to the |
406
|
|
|
|
|
|
|
Weasel::DriverRole protocol methods: |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
=over |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
=item set_wait_timeout |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
Sets the C<wait_timeut> attribute of the object as well as |
413
|
|
|
|
|
|
|
of the Selenium::Remote::Driver object, if a session has been |
414
|
|
|
|
|
|
|
started. |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=cut |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub set_wait_timeout { |
419
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
420
|
0
|
|
|
|
|
|
my $driver = $self->_driver; |
421
|
|
|
|
|
|
|
|
422
|
0
|
0
|
|
|
|
|
$driver->set_implicit_wait_timeout($value) |
423
|
|
|
|
|
|
|
if defined $driver; |
424
|
0
|
|
|
|
|
|
return $self->_set_wait_timeout($value); |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=item set_window_size |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
Sets the C<window_size> attribute of the object as well as the |
430
|
|
|
|
|
|
|
window size of the currently active window of the Selenium::Remote::Driver |
431
|
|
|
|
|
|
|
object, if a session has been started. |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
=cut |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
sub set_window_size { |
436
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
437
|
0
|
|
|
|
|
|
my $driver = $self->_driver; |
438
|
|
|
|
|
|
|
|
439
|
0
|
0
|
|
|
|
|
$driver->set_window_size(split /x/, $value) |
440
|
|
|
|
|
|
|
if defined $driver; |
441
|
0
|
|
|
|
|
|
return $self->_set_window_size($value); |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=back |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=cut |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
# PRIVATE IMPLEMENTATIONS |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
sub _resolve_id { |
452
|
0
|
|
|
0
|
|
|
my ($self, $id) = @_; |
453
|
|
|
|
|
|
|
|
454
|
0
|
0
|
|
|
|
|
if (ref $id) { |
455
|
0
|
|
|
|
|
|
return $id; |
456
|
|
|
|
|
|
|
} |
457
|
|
|
|
|
|
|
else { |
458
|
0
|
|
|
|
|
|
my @rv = $self->_driver->find_elements($id,'xpath'); |
459
|
0
|
|
|
|
|
|
return (shift @rv); |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
sub _scroll { |
464
|
0
|
|
|
0
|
|
|
my ($self, $id) = @_; |
465
|
|
|
|
|
|
|
|
466
|
0
|
|
|
|
|
|
$self->_driver->execute_script('arguments[0].scrollIntoView(' |
467
|
|
|
|
|
|
|
. '{block: "center", ' |
468
|
|
|
|
|
|
|
. 'inline: "center", ' |
469
|
|
|
|
|
|
|
. 'behavior: "smooth"' |
470
|
|
|
|
|
|
|
. '});', |
471
|
|
|
|
|
|
|
$id); |
472
|
0
|
|
|
|
|
|
return $id; |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
=head1 AUTHOR |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
Erik Huelsmann |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
=over |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
=item Erik Huelsmann |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=item Yves Lavoie |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=back |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
=head1 MAINTAINERS |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
Erik Huelsmann |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
Bugs can be filed in the GitHub issue tracker for the Weasel project: |
498
|
|
|
|
|
|
|
https://github.com/perl-weasel/weasel-driver-selenium2/issues |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=head1 SOURCE |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
The source code repository for Weasel is at |
503
|
|
|
|
|
|
|
https://github.com/perl-weasel/weasel-driver-selenium2 |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=head1 SUPPORT |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
Community support is available through |
508
|
|
|
|
|
|
|
L<perl-weasel@googlegroups.com|mailto:perl-weasel@googlegroups.com>. |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
(C) 2016-2020 Erik Huelsmann |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
Licensed under the same terms as Perl. |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=cut |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
1; |