File: Dojo.pm

package info (click to toggle)
libweasel-widgets-dojo-perl 0.07-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 181; makefile: 2
file content (116 lines) | stat: -rw-r--r-- 2,440 bytes parent folder | download
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

=head1 NAME

Weasel::FindExpanders::Dojo - XPath mnemonic hooks for Dojo 1.x widgets

=head1 VERSION

0.02

=head1 SYNOPSIS

  use Weasel::FindExpanders::Dojo;

  my $button = $session->find($session->page, "@button|{text=>\"whatever\"}");

=cut

package Weasel::FindExpanders::Dojo;

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' matches content between open and close tag

=cut

sub button_expander {
    my %args = @_;

    my @clauses;
    if (defined $args{text}) {
        push @clauses, "text()='$args{text}'";
    }

    for my $clause (qw/ id name /) {
        if (defined $args{$clause}) {
            push @clauses, "\@$clause='$args{$clause}'";
        }
    }

    my $clause =
        (@clauses) ? ('and .//*[' . join(' and ', @clauses) . ']'): '';

    # dijitButtonNode has a click handler
    # (its parent is has the dijitButton class, but only has a submit handler)
    return ".//*[contains(concat(' ',normalize-space(\@class),' '),
                                 ' dijitButtonNode ') $clause]"


}

=item option_expander

Finds options for dijit.form.Select, after the drop down has been invoked
at least once (the options don't exist in the DOM tree before that point).

Because of that, it's best to search the options through the C<select> tag,
which offers a C<find_option> method which specifically compensates for the
issue.

Additionally, it's impossible to search options by the value being submitted;
these don't exist in the DOM tree unlike with the C<option> tags of
C<select>s.

Criteria:
 * 'id'
 * 'text' matches the visible description of the item

=cut

sub option_expander {
    my %args = @_;

    my @clauses;
    if (defined $args{text}) {
        push @clauses, "text()='$args{text}'";
    }

    for my $clause (qw/ id /) {
        if (defined $args{$clause}) {
            push @clauses, "\@$clause='$args{$clause}'";
        }
    }

    my $clause =
        (@clauses) ? ('and .//*[' . join(' and ', @clauses) . ']'): '';
    return ".//*[\@role='option' $clause]";
}


=back

=cut



register_find_expander($_->{name}, 'Dojo', $_->{expander})
    for ({  name => 'button',   expander => \&button_expander   },
         {  name => 'option',   expander => \&option_expander   },
    );


1;