AnyEvent-WebDriver

 view release on metacpan or  search on metacpan

WebDriver.pm  view on Meta::CPAN

      },
   ]);

And here is essentially the same (except for fewer pauses) example as
above, using the much simpler C<AnyEvent::WebDriver::Actions> API:

   $wd->navigate_to ("https://duckduckgo.com/html");
   my $input = $wd->find_element ("css selector", 'input[type="text"]');
   $wd->actions
      ->move ($input, 40, 5, "touch1")
      ->click
      ->key ("a")
      ->key ("b")
      ->pause (2000) # so you can watch leisurely
      ->key ("{Enter}")
      ->pause (5000) # so you can see the result
      ->perform;

=item $wd->release_actions

Release all keys and pointer buttons currently depressed.

=cut

sub perform_actions_ {
   if (UNIVERSAL::isa $_[1], AnyEvent::WebDriver::Actions::) {
      my ($actions, $duration) = $_[1]->compile;
      local $_[0]{timeout} = $_[0]{timeout} + $duration * 1e-3;
      $_[0]->post_ (actions => { actions => $actions }, $_[2]);
   } else {
      $_[0]->post_ (actions => { actions => $_[1] }, $_[2]);
   }
}

sub release_actions_ {
   $_[0]->delete_ (actions => $_[1]);
}

=back

=head3 USER PROMPTS

=over

=cut

=item $wd->dismiss_alert

Dismiss a simple dialog, if present.

=item $wd->accept_alert

Accept a simple dialog, if present.

=item $text = $wd->get_alert_text

Returns the text of any simple dialog.

=item $text = $wd->send_alert_text

Fills in the user prompt with the given text.


=cut

sub dismiss_alert_ {
   $_[0]->post_ ("alert/dismiss" => undef, $_[1]);
}

sub accept_alert_ {
   $_[0]->post_ ("alert/accept" => undef, $_[1]);
}

sub get_alert_text_ {
   $_[0]->get_ ("alert/text" => $_[1]);
}

sub send_alert_text_ {
   $_[0]->post_ ("alert/text" => { text => "$_[1]" }, $_[2]);
}

=back

=head3 SCREEN CAPTURE

=over

=cut

=item $wd->take_screenshot

Create a screenshot, returning it as a PNG image. To decode and save, you
could do something like:

   use MIME::Base64 ();

   my $screenshot = $wd->take_screenshot;

   open my $fh, ">", "screenshot.png" or die "screenshot.png: $!\n";

   syswrite $fh, MIME::Base64::decode_base64 $screenshot;

=item $wd->take_element_screenshot ($element)

Similar to C<take_screenshot>, but only takes a screenshot of the bounding
box of a single element.

Compatibility note: As of chrome version 80, I found that the screenshot
scaling is often wrong (the screenshot is much smaller than the element
normally displays) unless chrome runs in headless mode. The spec does
allow for any form of scaling, so this is not strictly a bug in chrome,
but of course it diminishes trhe screenshot functionality.

=cut

sub take_screenshot_ {
   my $cb = pop; push @_, sub { $cb->($_[0], _decode_base64 $_[1]) };
   $_[0]->get_ (screenshot => $_[1]);
}

sub take_element_screenshot_ {



( run in 0.558 second using v1.01-cache-2.11-cpan-6aa56a78535 )