| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Selenium::ActionChains; |
|
2
|
|
|
|
|
|
|
$Selenium::ActionChains::VERSION = '1.50'; |
|
3
|
1
|
|
|
1
|
|
239092
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
75
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Action chains for Selenium::Remote::Driver |
|
7
|
1
|
|
|
1
|
|
1057
|
use Moo; |
|
|
1
|
|
|
|
|
12344
|
|
|
|
1
|
|
|
|
|
5
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'driver' => ( is => 'ro', ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'actions' => ( |
|
13
|
|
|
|
|
|
|
is => 'lazy', |
|
14
|
0
|
|
|
0
|
|
|
builder => sub { [] }, |
|
15
|
|
|
|
|
|
|
clearer => 1, |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub perform { |
|
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
20
|
0
|
|
|
|
|
|
foreach my $action ( @{ $self->actions } ) { |
|
|
0
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$action->(); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub click { |
|
26
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
27
|
0
|
|
|
|
|
|
my $element = shift; |
|
28
|
0
|
0
|
|
|
|
|
if ($element) { |
|
29
|
0
|
|
|
|
|
|
$self->move_to_element($element); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# left click |
|
33
|
0
|
|
|
0
|
|
|
push @{ $self->actions }, sub { $self->driver->click('LEFT') }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub click_and_hold { |
|
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
39
|
0
|
|
|
|
|
|
my $element = shift; |
|
40
|
0
|
0
|
|
|
|
|
if ($element) { |
|
41
|
0
|
|
|
|
|
|
$self->move_to_element($element); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
0
|
|
|
0
|
|
|
push @{ $self->actions }, sub { $self->driver->button_down }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub context_click { |
|
48
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
49
|
0
|
|
|
|
|
|
my $element = shift; |
|
50
|
0
|
0
|
|
|
|
|
if ($element) { |
|
51
|
0
|
|
|
|
|
|
$self->move_to_element($element); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# right click |
|
55
|
0
|
|
|
0
|
|
|
push @{ $self->actions }, sub { $self->driver->click('RIGHT') }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub double_click { |
|
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
61
|
0
|
|
|
|
|
|
my $element = shift; |
|
62
|
0
|
0
|
|
|
|
|
if ($element) { |
|
63
|
0
|
|
|
|
|
|
$self->move_to_element($element); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
0
|
|
|
0
|
|
|
push @{ $self->actions }, sub { $self->driver->double_click }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub release { |
|
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
71
|
0
|
|
|
|
|
|
my $element = shift; |
|
72
|
0
|
0
|
|
|
|
|
if ($element) { |
|
73
|
0
|
|
|
|
|
|
$self->move_to_element($element); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
0
|
|
|
0
|
|
|
push @{ $self->actions }, sub { $self->driver->button_up }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub drag_and_drop { |
|
80
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
81
|
0
|
|
|
|
|
|
my ( $source, $target ) = @_; |
|
82
|
0
|
|
|
|
|
|
$self->click_and_hold($source); |
|
83
|
0
|
|
|
|
|
|
$self->release($target); |
|
84
|
0
|
|
|
|
|
|
$self; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub drag_and_drop_by_offset { |
|
88
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
89
|
0
|
|
|
|
|
|
my ( $source, $xoffset, $yoffset ) = @_; |
|
90
|
0
|
|
|
|
|
|
$self->click_and_hold($source); |
|
91
|
0
|
|
|
|
|
|
$self->move_by_offset( $xoffset, $yoffset ); |
|
92
|
0
|
|
|
|
|
|
$self->release($source); |
|
93
|
0
|
|
|
|
|
|
$self; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub move_to_element { |
|
97
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
98
|
0
|
|
|
|
|
|
my $element = shift; |
|
99
|
0
|
|
|
|
|
|
push @{ $self->actions }, |
|
100
|
0
|
|
|
0
|
|
|
sub { $self->driver->move_to( element => $element ) }; |
|
|
0
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub move_by_offset { |
|
105
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
106
|
0
|
|
|
|
|
|
my ( $xoffset, $yoffset ) = @_; |
|
107
|
0
|
|
|
|
|
|
push @{ $self->actions }, sub { |
|
108
|
0
|
|
|
0
|
|
|
$self->driver->move_to( xoffset => $xoffset, yoffset => $yoffset ); |
|
109
|
0
|
|
|
|
|
|
}; |
|
110
|
0
|
|
|
|
|
|
$self; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub move_to_element_with_offset { |
|
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
115
|
0
|
|
|
|
|
|
my ( $element, $xoffset, $yoffset ) = @_; |
|
116
|
0
|
|
|
|
|
|
push @{ $self->actions }, sub { |
|
117
|
0
|
|
|
0
|
|
|
$self->driver->move_to( |
|
118
|
|
|
|
|
|
|
element => $element, |
|
119
|
|
|
|
|
|
|
xoffset => $xoffset, |
|
120
|
|
|
|
|
|
|
yoffset => $yoffset |
|
121
|
|
|
|
|
|
|
); |
|
122
|
0
|
|
|
|
|
|
}; |
|
123
|
0
|
|
|
|
|
|
$self; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub key_down { |
|
127
|
0
|
|
|
0
|
1
|
|
my ( $self, $value, $element ) = @_; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#DWIM |
|
130
|
0
|
0
|
|
|
|
|
$value = [$value] unless ref $value eq 'ARRAY'; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
$self->click($element) if defined $element; |
|
133
|
0
|
|
|
|
|
|
foreach my $v (@$value) { |
|
134
|
0
|
|
|
|
|
|
push @{ $self->actions }, |
|
135
|
0
|
|
|
0
|
|
|
sub { $self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyDown', value => $v } ] } ] ) }; |
|
|
0
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
|
137
|
0
|
|
|
|
|
|
return $self; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub key_up { |
|
141
|
0
|
|
|
0
|
1
|
|
my ( $self, $value, $element ) = @_; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#DWIM |
|
144
|
0
|
0
|
|
|
|
|
$value = [$value] unless ref $value eq 'ARRAY'; |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
$self->click($element) if defined $element; |
|
147
|
0
|
|
|
|
|
|
foreach my $v (@$value) { |
|
148
|
0
|
|
|
|
|
|
push @{ $self->actions }, |
|
149
|
0
|
|
|
0
|
|
|
sub { $self->driver->general_action( actions => [ { type => 'key', id => 'key', actions => [ { type => 'keyUp', value => $v } ] } ] ) }; |
|
|
0
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} |
|
151
|
0
|
|
|
|
|
|
return $self; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub send_keys { |
|
155
|
0
|
|
|
0
|
1
|
|
my ($self,$keys) =@_; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Do nothing if there are no keys to send |
|
158
|
0
|
0
|
|
|
|
|
return unless $keys; |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# DWIM |
|
161
|
0
|
0
|
|
|
|
|
$keys = [split('',$keys)] unless ref $keys eq 'ARRAY'; |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
push @{ $self->actions }, |
|
164
|
|
|
|
|
|
|
sub { |
|
165
|
0
|
|
|
0
|
|
|
foreach my $key (@$keys) { |
|
166
|
0
|
|
|
|
|
|
$self->key_down($key, $self->driver->get_active_element); |
|
167
|
0
|
|
|
|
|
|
$self->key_up($key, $self->driver->get_active_element); |
|
168
|
|
|
|
|
|
|
} |
|
169
|
0
|
|
|
|
|
|
}; |
|
170
|
0
|
|
|
|
|
|
$self; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub send_keys_to_element { |
|
174
|
0
|
|
|
0
|
1
|
|
my ($self, $element, $keys) =@_; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Do nothing if there are no keys to send |
|
177
|
0
|
0
|
|
|
|
|
return unless $keys; |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# DWIM |
|
180
|
0
|
0
|
|
|
|
|
$keys = [split('',$keys)] unless ref $keys eq 'ARRAY'; |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
push @{ $self->actions }, |
|
183
|
|
|
|
|
|
|
sub { |
|
184
|
0
|
|
|
0
|
|
|
foreach my $key (@$keys) { |
|
185
|
0
|
|
|
|
|
|
$self->key_down($key,$element); |
|
186
|
0
|
|
|
|
|
|
$self->key_up($key,$element); |
|
187
|
|
|
|
|
|
|
} |
|
188
|
0
|
|
|
|
|
|
}; |
|
189
|
0
|
|
|
|
|
|
$self; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
__END__ |