AnyEvent-WebDriver

 view release on metacpan or  search on metacpan

WebDriver.pm  view on Meta::CPAN

=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_ {
   my $cb = pop; push @_, sub { $cb->($_[0], _decode_base64 $_[1]) };
   $_[0]->get_ ("element/$_[1]{$WEB_ELEMENT_IDENTIFIER}/screenshot" => $_[2]);
}

=back

=head3 PRINT

=over

=cut

=item $wd->print_page (key => value...)

Create a printed version of the document, returning it as a PDF document
encoded as base64. See C<take_screenshot> for an example on how to decode
and save such a string.

This command takes a lot of optional parameters, see L<the print
section|https://www.w3.org/TR/webdriver2/#print> of the WebDriver
specification for details.

This command is taken from a draft document, so it might change in the
future.

=cut

sub print_page {
   my $cb = pop; push @_, sub { $cb->($_[0], _decode_base64 $_[1]) };
   $_[0]->post_ (print => { @_ });
}

=head2 ACTION LISTS

Action lists can be quite complicated. Or at least it took a while for
me to twist my head around them. Basically, an action list consists of a
number of sources representing devices (such as a finger, a mouse, a pen
or a keyboard) and a list of actions for each source, in a timeline.



( run in 0.775 second using v1.01-cache-2.11-cpan-df04353d9ac )