WebDriver
- automate browser interaction with Selenium WebDriver
package require WebDriver
set caps [WebDriver::Capabilities #auto -browser_name firefox]
set session [WebDriver::Session #auto \
http://127.0.0.1:4444/wd/hub \
[namespace which $caps] \
]
$session set_logging_enabled true
set window [$session active_window]
$window maximize
$window set_url http://www.example.com
set element [$window element by_id username]
$element click
$element clear
$element send_keys "jonathan"
itcl::delete object $element
itcl::delete object $session
The WebDriver
module implements the Selenium WebDriver protocol. In order to
execute WebDriver tests, you will also need a copy of Selenium Server, which
you can download from http://seleniumhq.org
.
Server and test scripts can run on different systems as the server is controlled via remote procedure calls over a TCP connection. It is the server's responsibility to launch a browser instance and to forward the commands it receives from a test script.
proc sessions
url
WebDriver::Session
objects, one for each active session.constructor
url desired_capabilities ?required_capabilities?The desired_capabilities parameter is a reference to a
WebDriver::Capabilities
object. Desired means in this context that the
requested session properties are not mandatory for test execution.
The required_capablities parameter is a reference to a
WebDriver::RequiredCapabilities
object. Required means in this context
that the requested session properties are mandatory for test execution.
If they cannot be full-filled an exception is thrown.
method active_window
WebDriver::Window
object. The window reference is managed by the
session and must not be deleted.
Throws a WebDriver::NoSuchWindowError
error, if the window has been
closed.
method capabilities
WebDriver::Capabilities
object.method get_log
type
log_types
) from the
server. Returns a list of raw log items.method logging_enabled
method log_types
method set_logging_enabled
bool
method set_async_script_timeout
ms
method set_implicit_wait_timeout
ms
method set_page_load_timeout
ms
method windows
focus
method. The window
references are managed by the session and must not be deleted.constructor
Session
methods active_window
and windows
. There is absolutely no
point in constructing a window manually.method accept_alert
Throws a WebDriver::NoAlertOpenError
if no alert is being displayed.
method active_element
WebDriver::WebElement
reference to the page element that currently
has the focus.method alert_send_text
text
Throws a WebDriver::NoAlertOpenError
if no alert is being displayed.
method alert_text
alert()
, confirm()
,
or prompt()
dialog.
Throws a WebDriver::NoAlertOpenError
if no alert is being displayed.
method back
method button_down
?button?click
method instead.method button_up
?button?button
is not specified, the left
button is assumed.method close
WebDriver::CloseSessionWindowError
will be thrown.method cookies
WebDriver::Cookie
object references. The cookies are a property of the
Window
object and must not be deleted.method delete_cookie
name
method dismiss_alert
confirm()
and prompt()
dialogs, this is equivalent to clicking the "Cancel" button. For alert()
dialogs, this is equivalent to clicking the "OK" button.
Throws a WebDriver::NoAlertOpenError
if no alert is being displayed.
method doubleclick
method element
strategy locator
WebDriver::WebElement
instance. The strategy can be one of
* by_class_name,
* by_css_selector,
* by_id,
* by_name,
* by_link_text,
* by_partial_link_text,
* by_tag_name,
* by_xpath
and the locator would be the corresponding specifier. This method only ever returns one element (the first one that matches). Element references obtained by this method must be explicitly deleted when not used anymore.
Throws a WebDriver::NoSuchElementError
if the element cannot be found
and a WebDriver::XPathLookupError
if an invalid expression was supplied.
method elements
strategy locator
element
above but, as the name suggests, will
return a list of all elements that match the given locator. Element
references obtained by this method must be explicitly deleted when not
used anymore.
May return an empty list. Throws a WebDriver::XPathLookupError
if an
invalid expression was supplied.
method execute
script ?arg arg ...?arguments
inside
the script.
Throws a WebDriver::StaleElementReferenceError
if one of the script
arguments is a WebElement
that is not attached to the page's DOM or a
WebDriver::JavaScriptError
if the injected script throws an Error.
method execute_async
?-joinable
? ?-result
varname element? ?-error
varname element? script
-joinable
flag is set, the thread can be waited on with thread::join
. The
-result
parameter specifies the name of a thread shared variable, as described
in tsv
(3tcl), under which to store the script result. In the same way an
error variable can be specified, which will hold information about any error
that occurred during script execution.
This method is processed in a separate thread. If an error occurrs during
script execution, the thread shared variable specified via the -error
parameter will contain a description of the error.
method focus
method forward
method maximize
method move_to
xoffset yoffset
move_to
method.method name
method orientation
method page_source
method page_title
method position
{x y}
.method refresh
method screenshot
?-decode
?-decode
parameter
is given, the return value is the raw PNG, otherwise the image is
Base64-encoded.method select_frame
?id?WebDriver::WebElement
object
identifying the frame. If id is not specified, Selenium Server will select
the default content of the page.method session
method set_cookie
?-path
string? ?-domain
string? ?-secure
? ?-http_only
? ?-expiry
timestamp? name
-domain
parameter. The -expiry
of the cookie must be a Unix timestamp indicating the
time of expiry as seconds since midnight Jan 1, 1970 UTC.
Throws a WebDriver::InvalidCookieDomainError
if the cookie domain is not
visible from the current page or a WebDriver::UnableToSetCookieError
if
trying to set a cookie on a page that doesn't support cookies.
method set_orientation
orientation
method set_position
x y
method set_size
width height
method set_url
url
method size
{width height}
.method url
constructor
WebElement
instances are obtained by calling the element
or elements
methods on a WebDriver::Window
object. Elements cannot be injected into the
page (you can of course inject JavaScript to do something like that). Thus
there is no point in constructing a WebElement
manually.method attribute
name
name
.method clear
textarea
or an input
element's value.
Throws a WebDriver::StaleElementReferenceError
if the element is no longer
attached to the page's DOM, a WebDriver::ElementNotVisibleError
if the
element is not visible on the page or a WebDriver::InvalidElementStateError
if the referenced element is disabled.
method click
Throws a WebDriver::StaleElementReferenceError
if the element is no longer
attached to the page's DOM or a WebDriver::ElementNotVisibleError
if the
element is not visible on the page.
method css_property
name
method descendant
strategy locator
Window::element
, but only searches the
element tree below the current element.
Throws a WebDriver::NoSuchElementError
if the element cannot be found
and a WebDriver::XPathLookupError
if an invalid expression was supplied.
method descendants
strategy locator
Window::elements
, but only searches the
element tree below the current element.
May return an empty list. Throws a WebDriver::XPathLookupError
if an
invalid expression was supplied.
method displayed
method enabled
method location
{x y}
.
The point {0 0}
refers to the top left corner of the canvas.method move_to
?xoffset? ?yoffset?method selected
option
element, or an input
element of type checkbox
or radiobutton is currently selected.method send_keys
string
method size
{width height}
.method submit
form
element. This command may also be applied to any element
that is a descendant of a form
element.method tag_name
method text
constructor
?-domain
name? ?-expiry
timestamp? ?-http_only
bool? ?-path
name? ?-secure
bool? name value
Cookie
manually. Most of the
time, you will just retrieve cookies via a WebDriver::Window
object, or you
will set cookies using the Window
class' set_cookie
convenience method.method domain
method expiry
method http_only
method name
method path
method secure
method value
method set_domain
string
method set_expiry
timestamp
method set_http_only
bool
method set_name
string
method set_path
string
method set_secure
bool
method set_value
string
constructor
?-browser_name
string? ?-version
string? ?-platform
string? ?-javascript_enabled
bool? ?-takes_screenshot
bool? ?-handles_alerts
bool? ?-database_enabled
bool? ?-location_context_enabled
bool? ?-application_cache_enabled
bool? ?-browser_connection_enabled
bool? ?-css_selectors_enabled
bool? ?-web_storage_enabled
bool? ?-rotatable
bool? ?-accept_ssl_certs
bool? ?-native_events
bool? ?-proxy
proxy_obj?Capabilities
are used to request session properties during initialization of
a WebDriver::Session
.method accept_ssl_certs
method application_cache_enabled
method browser_connection_enabled
method browser_name
method css_selectors_enabled
method database_enabled
method handles_alerts
window.alert
and window.confirm
.method javascript_enabled
method location_context_enabled
method native_events
method platform
method proxy
WebDriver::Proxy
object that indicates the connection type.method rotatable
method takes_screenshot
method version
method web_storage_enabled
method set_accept_ssl_certs
bool
method set_application_cache_enabled
bool
method set_browser_connection_enabled
bool
method set_browser_name
string
{chrome|firefox|htmlunit|internet explorer|iphone}
.method set_css_selectors_enabled
bool
method set_database_enabled
bool
method set_handles_alerts
bool
window.alert
and window.confirm
.method set_javascript_enabled
bool
method set_location_context_enabled
bool
method set_native_events
bool
method set_platform
string
{WINDOWS|XP|VISTA|MAC|LINUX|UNIX}
. When requesting a new session, the
client may specify ANY
to indicate any available platform may be used.method set_proxy
proxy_object
WebDriver::Proxy
object.method set_rotatable
bool
method set_takes_screenshot
bool
method set_version
string
method set_web_storage_enabled
bool
The RequiredCapabilities
class is identical to the Capabilities
class with
the sole difference being that RequiredCapabilities
objects don't carry any
default values.
constructor
?-ftp_proxy
url? ?-http_proxy
url? ?-proxy_type
type? ?-proxy_autoconfig_url
url? ?-ssl_proxy
url?Proxy
object is passed to the session constructor as part of the desired
or required capabilities.method ftp_proxy
method http_proxy
method proxy_type
method proxy_autoconfig_url
method ssl_proxy
method set_ftp_proxy
url
method set_http_proxy
url
method set_proxy_type type
method set_proxy_autoconfig_url
url
method set_ssl_proxy
url
While the Session
methods logging_enabled
and set_logging_enabled
deal
with local logging functionality of the WebDriver
package itself, the methods
log_types
and get_log
are for retrieving logs from the server instead.
itcl
(3), error
(3caius)