line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Brownie::XPath; |
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
108
|
use strict; |
|
19
|
|
|
|
|
36
|
|
|
19
|
|
|
|
|
737
|
|
4
|
19
|
|
|
19
|
|
102
|
use warnings; |
|
19
|
|
|
|
|
38
|
|
|
19
|
|
|
|
|
466
|
|
5
|
19
|
|
|
19
|
|
21412
|
use HTML::Selector::XPath (); |
|
19
|
|
|
|
|
67983
|
|
|
19
|
|
|
|
|
10707
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub to_xpath { |
8
|
287
|
|
|
287
|
0
|
538
|
my $locator = shift; |
9
|
|
|
|
|
|
|
# taken from Web::Scraper |
10
|
287
|
100
|
|
|
|
2460
|
return $locator =~ m!^(?:/|id\()! |
11
|
|
|
|
|
|
|
? $locator # XPath |
12
|
|
|
|
|
|
|
: HTML::Selector::XPath::selector_to_xpath($locator); # CSS to XPath |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub to_link { |
16
|
4
|
|
|
4
|
0
|
17
|
my $locator = shift; |
17
|
4
|
|
|
|
|
12
|
return join '|', map { sprintf $_, $locator } ( |
|
20
|
|
|
|
|
90
|
|
18
|
|
|
|
|
|
|
q!//a[@id='%s']!, |
19
|
|
|
|
|
|
|
q!//a[@name='%s']!, |
20
|
|
|
|
|
|
|
q!//a[@title='%s']!, |
21
|
|
|
|
|
|
|
q!//a[text()[contains(.,'%s')]]!, |
22
|
|
|
|
|
|
|
q!//a//img[@alt='%s']!, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub to_button { |
27
|
58
|
|
|
58
|
0
|
115
|
my $locator = shift; |
28
|
58
|
|
|
|
|
177
|
return join '|', map { sprintf $_, $locator } ( |
|
580
|
|
|
|
|
1890
|
|
29
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @id='%s']!, |
30
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @name='%s']!, |
31
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @title='%s']!, |
32
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @value='%s']!, |
33
|
|
|
|
|
|
|
q!//input[@type='image' and @alt='%s']!, |
34
|
|
|
|
|
|
|
q!//button[@id='%s']!, |
35
|
|
|
|
|
|
|
q!//button[@name='%s']!, |
36
|
|
|
|
|
|
|
q!//button[@title='%s']!, |
37
|
|
|
|
|
|
|
q!//button[@value='%s']!, |
38
|
|
|
|
|
|
|
q!//button[text()[contains(.,'%s')]]!, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub to_link_or_button { |
43
|
11
|
|
|
11
|
0
|
24
|
my $locator = shift; |
44
|
11
|
|
|
|
|
44
|
return join '|', map { sprintf $_, $locator } ( |
|
165
|
|
|
|
|
468
|
|
45
|
|
|
|
|
|
|
q!//a[@id='%s']!, |
46
|
|
|
|
|
|
|
q!//a[@name='%s']!, |
47
|
|
|
|
|
|
|
q!//a[@title='%s']!, |
48
|
|
|
|
|
|
|
q!//a[text()[contains(.,'%s')]]!, |
49
|
|
|
|
|
|
|
q!//a//img[@alt='%s']!, |
50
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @id='%s']!, |
51
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @name='%s']!, |
52
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @title='%s']!, |
53
|
|
|
|
|
|
|
q!//input[(@type='submit' or @type='button' or @type='image') and @value='%s']!, |
54
|
|
|
|
|
|
|
q!//input[@type='image' and @alt='%s']!, |
55
|
|
|
|
|
|
|
q!//button[@id='%s']!, |
56
|
|
|
|
|
|
|
q!//button[@name='%s']!, |
57
|
|
|
|
|
|
|
q!//button[@title='%s']!, |
58
|
|
|
|
|
|
|
q!//button[@value='%s']!, |
59
|
|
|
|
|
|
|
q!//button[text()[contains(.,'%s')]]!, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub to_text_field { |
64
|
12
|
|
|
12
|
0
|
32
|
my $locator = shift; |
65
|
12
|
|
|
|
|
40
|
return join '|', map { sprintf $_, $locator } ( |
|
132
|
|
|
|
|
470
|
|
66
|
|
|
|
|
|
|
q!//input[(@type='text' or @type='password' or @type='hidden' or not(@type)) and @id='%s']!, |
67
|
|
|
|
|
|
|
q!//input[(@type='text' or @type='password' or @type='hidden' or not(@type)) and @name='%s']!, |
68
|
|
|
|
|
|
|
q!//input[(@type='text' or @type='password' or @type='hidden' or not(@type)) and @title='%s']!, |
69
|
|
|
|
|
|
|
q!//input[(@type='text' or @type='password' or @type='hidden' or not(@type)) and @value='%s']!, |
70
|
|
|
|
|
|
|
q!//input[(@type='text' or @type='password' or @type='hidden' or not(@type)) and @id=//label[text()[contains(.,'%s')]]/@for]!, |
71
|
|
|
|
|
|
|
q!//label[text()[contains(.,'%s')]]//input[(@type='text' or @type='password' or @type='hidden' or not(@type))]!, |
72
|
|
|
|
|
|
|
q!//textarea[@id='%s']!, |
73
|
|
|
|
|
|
|
q!//textarea[@name='%s']!, |
74
|
|
|
|
|
|
|
q!//textarea[@title='%s']!, |
75
|
|
|
|
|
|
|
q!//textarea[@id=//label[text()[contains(.,'%s')]]/@for]!, |
76
|
|
|
|
|
|
|
q!//label[text()[contains(.,'%s')]]//textarea!, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub to_radio { |
81
|
9
|
|
|
9
|
0
|
18
|
my $locator = shift; |
82
|
9
|
|
|
|
|
24
|
return join '|', map { sprintf $_, $locator } ( |
|
54
|
|
|
|
|
176
|
|
83
|
|
|
|
|
|
|
q!//input[@type='radio' and @id='%s']!, |
84
|
|
|
|
|
|
|
q!//input[@type='radio' and @name='%s']!, |
85
|
|
|
|
|
|
|
q!//input[@type='radio' and @title='%s']!, |
86
|
|
|
|
|
|
|
q!//input[@type='radio' and @value='%s']!, |
87
|
|
|
|
|
|
|
q!//input[@type='radio' and @id=//label[text()[contains(.,'%s')]]/@for]!, |
88
|
|
|
|
|
|
|
q!//label[text()[contains(.,'%s')]]//input[@type='radio']!, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub to_checkbox { |
93
|
12
|
|
|
12
|
0
|
31
|
my $locator = shift; |
94
|
12
|
|
|
|
|
31
|
return join '|', map { sprintf $_, $locator } ( |
|
72
|
|
|
|
|
228
|
|
95
|
|
|
|
|
|
|
q!//input[@type='checkbox' and @id='%s']!, |
96
|
|
|
|
|
|
|
q!//input[@type='checkbox' and @name='%s']!, |
97
|
|
|
|
|
|
|
q!//input[@type='checkbox' and @title='%s']!, |
98
|
|
|
|
|
|
|
q!//input[@type='checkbox' and @value='%s']!, |
99
|
|
|
|
|
|
|
q!//input[@type='checkbox' and @id=//label[text()[contains(.,'%s')]]/@for]!, |
100
|
|
|
|
|
|
|
q!//label[text()[contains(.,'%s')]]//input[@type='checkbox']!, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub to_option { |
105
|
21
|
|
|
21
|
0
|
47
|
my $locator = shift; |
106
|
21
|
|
|
|
|
55
|
return join '|', map { sprintf $_, $locator } ( |
|
105
|
|
|
|
|
402
|
|
107
|
|
|
|
|
|
|
q!//option[@id='%s']!, |
108
|
|
|
|
|
|
|
q!//option[@name='%s']!, |
109
|
|
|
|
|
|
|
q!//option[@title='%s']!, |
110
|
|
|
|
|
|
|
q!//option[@value='%s']!, |
111
|
|
|
|
|
|
|
q!//option[text()[contains(.,'%s')]]!, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub to_file_field { |
116
|
3
|
|
|
3
|
0
|
7
|
my $locator = shift; |
117
|
3
|
|
|
|
|
10
|
return join '|', map { sprintf $_, $locator } ( |
|
15
|
|
|
|
|
62
|
|
118
|
|
|
|
|
|
|
q!//input[@type='file' and @id='%s']!, |
119
|
|
|
|
|
|
|
q!//input[@type='file' and @name='%s']!, |
120
|
|
|
|
|
|
|
q!//input[@type='file' and @title='%s']!, |
121
|
|
|
|
|
|
|
q!//input[@type='file' and @id=//label[text()[contains(.,'%s')]]/@for]!, |
122
|
|
|
|
|
|
|
q!//label[text()[contains(.,'%s')]]//input[@type='file']!, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 NAME |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Brownie::XPath |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
NAKAGAWA Masaki Emasaki@cpan.orgE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 LICENSE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
139
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SEE ALSO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |