Finders.pm 837 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package Selenium::Remote::Finders;
  2. use strict;
  3. use warnings;
  4. # ABSTRACT: Handle construction of generic parameter finders
  5. use Try::Tiny;
  6. use Carp qw/carp/;
  7. use Moo::Role;
  8. use namespace::clean;
  9. =head1 DESCRIPTION
  10. This package just takes care of setting up parameter finders - that
  11. is, the C<find_element_by_.*> versions of the find element
  12. functions. You probably don't need to do anything with this package;
  13. instead, see L<Selenium::Remote::Driver/find_element> documentation
  14. for the specific finder functions.
  15. =cut
  16. sub _build_find_by {
  17. my ( $self, $by ) = @_;
  18. return sub {
  19. my ( $driver, $locator ) = @_;
  20. my $strategy = $by;
  21. return try {
  22. return $driver->find_element( $locator, $strategy );
  23. }
  24. catch {
  25. carp $_;
  26. return 0;
  27. };
  28. }
  29. }
  30. 1;