| Weasel::FindExpanders(3pm) | User Contributed Perl Documentation | Weasel::FindExpanders(3pm) |
Weasel::FindExpanders - Mapping find patterns to xpath locators
version 0.32
use Weasel::FindExpanders qw( register_find_expander );
register_find_expander(
'button',
'HTML',
sub {
my %args = @_;
$args{text} =~ s/'/''/g; # quote the quotes (XPath 2.0)
return ".//button[text()='$args{text}']";
});
$session->find($session->page, "*button|{text=>\"whatever\"}");
The concept of find expanders is used to define XPath templates for use with the "find" and "find_all" methods. Multiple patterns may be registered with the same pattern name ("mnemonic"); eg, there could be a two patterns associated with the "button" mnemonic, one for the "<button>" tag and one for the "<input type="submit">" tag. Or there could even be more patterns registered, eg., to match Vue, React or Web Component elements. All patterns registered on a single mnemonic (template name) will be compiled into a single XPath expression which will match any of the patterns.
Weasel comes with a standard set of patterns in the Weasel::FindExpanders::HTML package.
"Weasel::Session" selects the expanders to be applied using its "groups" attribute.
When $groups is undef, all groups will be searched for "pattern_name".
If the pattern doesn't match '*<pattern_name>|{<arguments>}', the pattern is returned as the only list/arrayref element.
Erik Huelsmann
Erik Huelsmann Yves Lavoie
Erik Huelsmann
Bugs can be filed in the GitHub issue tracker for the Weasel
project:
https://github.com/perl-weasel/weasel/issues
The source code repository for Weasel is at
https://github.com/perl-weasel/weasel
Community support is available through perl-weasel@googlegroups.com <mailto:perl-weasel@googlegroups.com>.
(C) 2016-2023 Erik Huelsmann
Licensed under the same terms as Perl.
| 2025-05-24 | perl v5.40.1 |