NAME

WWW::WebKit - Perl extension for controlling an embedding WebKit engine

SYNOPSIS

use WWW::WebKit;

my $webkit = WWW::WebKit->new(xvfb => 1);
$webkit->init;

$webkit->open("http://www.google.com");
$webkit->type("q", "hello world");
$webkit->click("btnG");
$webkit->wait_for_page_to_load(5000);
print $webkit->get_title;

DESCRIPTION

WWW::WebKit is a drop-in replacement for WWW::Selenium using Gtk3::WebKit as browser instead of relying on an external Java server and an installed browser.

EXPORT

None by default.

PROPERTIES

console_messages

WWW::WebKit saves console messages in this array but still lets the default console handler handle the message. I'm not sure if this is the best way to go but you should be able to override this easily:

use Glib qw(TRUE FALSE);
$webkit->view->signal_connect('console-message' => sub {
    push @{ $webkit->console_messages }, $_[1];
    return TRUE;
});

The TRUE return value prevents any further handlers from kicking in which in turn should prevent any messages from getting printed.

METHODS

init

Initializes Webkit and GTK3. Must be called before any of the other methods.

Implemented methods of the Selenium API

Please see WWW::Selenium for the full documentation of these methods.

set_timeout($timeout)

Set the default timeout to $timeout.

open($url)

refresh()

go_back()

get_xpath_count

select($select, $option)

click($locator)

check($locator)

uncheck($locator)

wait_for_page_to_load($timeout)

wait_for_element_present($locator, $timeout)

is_element_present($locator)

get_text($locator)

type($locator, $text)

type_keys($locator, $string)

pause($time)

is_ordered($first, $second)

get_body_text()

get_title()

mouse_over($locator)

mouse_down($locator)

mouse_up($locator)

fire_mouse_event($locator, $event_type)

fire_event($locator, $event_type)

get_value($locator)

get_attribute($locator)

is_visible($locator)

submit($locator)

get_html_source()

Returns the source code of the current HTML page as it was transferred over the network.

Use $webkit->view->get_dom_document->get_document_element->get_outer_html to get the serialized current DOM tree (with all modifications by Javascript)

get_confirmation()

get_alert()

answer_on_next_confirm

answer_on_next_prompt($answer)

Additions to the Selenium API

wait_for_pending_requests($timeout)

Waits for all pending requests to finish. This is most useful for AJAX applications, since wait_for_page_to_load does not wait for AJAX requests.

wait_for_element_to_disappear($locator, $timeout)

Works just like wait_for_element_present but instead of waiting for the element to appear, it waits for the element to disappear.

wait_for_alert($text, $timeout)

Wait for an alert with the given text to happen. If $text is undef, it waits for any alert. Since alerts do not get automatically cleared, this has to be done manually before causing the action that is supposed to throw a new alert:

$webkit->alerts([]);
$webkit->click('...');
$webkit->wait_for_alert;

wait_for_condition($condition, $timeout)

Wait for the given $condition sub to return a true value or $timeout to expire. Returns the return value of $condition or 0 on timeout.

$webkit->wait_for_condition(sub {
    $webkit->is_visible('id=foo');
}, 10000);

native_drag_and_drop_to_position($source_locator, $target_x, $target_y, $options)

Drag source element and drop it to position $target_x, $target_y.

native_drag_and_drop_to_object($source_locator, $target_locator, $options)

Drag source element and drop it into target element.

disable_plugins()

Disables WebKit plugins. Use this if you don't need plugins like Java and Flash and want to for example silence plugin loading messages.

delete_text($locator)

Delete text in elements where contenteditable="true".

SEE ALSO

See WWW::Selenium for API documentation. See Test::WWW::WebKit for a replacement for Test::WWW::Selenium. See Test::WWW::WebKit::Catalyst for a replacement for Test::WWW::Selenium::Catalyst.

The current development version can be found in the git repository at: https://github.com/niner/WWW-WebKit

AUTHOR

Stefan Seifert, <nine@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Stefan Seifert

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.3 or, at your option, any later version of Perl 5 you may have available.