WebDriver.Session

This module runs a browser session. Use these functions to drive the browser. The ‘name’ parameter is always the session name atom that is set when you start the session.

Example Session:

iex(1)>  config = %WebDriver.Config{browser: :phantomjs, name: :test_browser}
%WebDriver.Config{browser: :phantomjs, name: :test_browser, root_url: ""}
iex(2)> WebDriver.start_browser config
{:ok, #PID<0.133.0>}
iex(3)> WebDriver.start_session :test_browser, :session_name
{:ok, #PID<0.137.0>}
iex(4)> WebDriver.Session.url :session_name, "http://www.google.com"
{:ok,
 %WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{"url":"http://www.google.com"}",
   headers: ["Content-Type": "application/json;charset=UTF-8",
    "Content-Length": 31], method: :POST,
   url: "http://localhost:53094/wd/hub/session/1f44bb00-2698-11e4-8216-49b0aee6bf1f/url"},
  session_id: "1f44bb00-2698-11e4-8216-49b0aee6bf1f", status: 0, value: %{}}}
iex(5)> WebDriver.Session.url :session_name
"http://www.google.com.au/?gfe_rd=cr&ei=ao7xU7TGNs3C8gednYCYBQ"
iex(6)> WebDriver.stop_session :session_name
:ok
iex(7)> WebDriver.stop_browser :test_browser
:ok
iex(8)>
Source

Summary

active_element(name)

Get the element on the page that currently has focus

back(name)

Navigate back in the browser history

close_window(name)

Closes the current window

cookies(name)

Retreive all the cookies associated with the current page

delete_cookie(name, cookie_name)

Delete the cookie with the given name

delete_cookies(name)

Delete all cookies for the current page

element(name, using, value)

Retreive an element from the page using the specified search strategy. Returns the first element found that fits the search criteria

element(name, using, value, start_element)

Retreive an element from the page starting from the specified element using the specified search strategy

elements(name, using, value)

Retreive all elements from the page using the specified search strategy

elements(name, using, value, start_element)

Retreive all elements starting from the specified element using the specified search strategy

execute(name, script, args \\ [])

Execute Javascript in the browser and return the result

execute_async(name, script, args \\ [])

Execute Javascript asynchronously in the browser and return the result

forward(name)

Navigate forward in the browser history

frame(name, id)

Change the frame that has focus in the current window. https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/frame

javascript_enabled?(name)

True if javascript is enabled for this session

keys(name, value)

Send a list of keystrokes to the currently active element. If you want to send non-printable keystrokes you must call Webdriver.Keys.key(key_symbol) to convert it properly

maximize_window(name, window_handle \\ "current")

Maximise the specified window. Use “current” or simply do not specify a handle to maximise the current window

negotiated_capabilities(name)

Returns the negotiated capabilities of the current session

orientation(name)

Get the current browser screen orientation. Only works on browsers with the rotatable capability

orientation(name, screen_orientation)

Set the current browser screen orientation https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/orientation

refresh(name)

Refresh the current page in the browser

rotatable?(name)

True if this session supports device rotation

screenshot(name)

Get a PNG screenshot of the current page

session(name)

Get details about the current session on the WebDriver server

sessions(name)

List all the sessions on the WebDriver browser

set_async_script_timeout(name, ms)

Set the script timeout for the session

set_cookie(name, cookie)

Set a cookie for the current page

set_cookie(name, cookie_name, value, path, domain, expiry \\ in_one_hour())
set_implicit_wait_timeout(name, ms)

Set the implicit wait timeout for the session

set_timeout(name, type, ms)

Set timeouts on the server. Parameters must include the type of timeout and the length in milliseconds (ms). Valid types are “script” and “implicit”

source(name)

Retreive the curent page source

start_link(state, name)

Starts the session

start_session(name, desired_capabilities \\ %{})

Start a session with the desired capabilities on the browser. This is automatically called when the Session server starts, but in some cases you may want to stop and restart sessions without stopping and restarting the Session server

status(name)

Returns the status of the WebDriver server

stop(name)

Stop the session

stop_session(name)

Stop the session with the given name. Does not stop the Erlang server, just sends a request to the WebDriver server to stop the session

takes_screenshot?(name)

True if this session can take screenshots

title(name)

Retreive the current page title

url(name)

Get the current page URL

url(name, url)

Navigate to the specified url

window(name, window_handle)

Change the focus to another window

window_handle(name)

Get the handle of the current window. A window handle is an opaque reference used for various window related functions

window_handles(name)

Get all the window handles associated with the browser. Returns a list of window handles

window_size(name)

Retreive the window size. If a window handle is not specified it retreives the current window

window_size(name, window_handle, width, height)

Set the window size

Functions

active_element(name)
Source
back(name)
Source
cookies(name)

Retreive all the cookies associated with the current page.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/cookie

Source
delete_cookie(name, cookie_name)
Source
delete_cookies(name)
Source
element(name, using, value)

Retreive an element from the page using the specified search strategy. Returns the first element found that fits the search criteria.

The return value is an element reference that can be used by functions in the WebDriver.Element module for further queries.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element

The parameter ‘using’ must be a valid search strategy. The parameter ‘value’ is a string to search for.

Valid search strategies are:

* :class - Search for an element with the given class attribute.
* :class_name - alias for :class
* :css - Search for an element using a CSS selector.
* :id - Find an element with the given id attribute.
* :name - Find an element with the given name attribute.
* :link - Find an link element containing the given text.
* :partial_link - Find a link element containing a superset of the given text.
* :tag - Find a HTML tag of the given type.
* :xpath - Use [XPath](http://www.w3.org/TR/xpath/) to search for an element.

Parameters [using :: atom, value :: String]

Returns: A (WebDriver.Element)[/WebDriver.Element.html] struct.

## Examples

iex(12)> WebDriver.Session.element :test, :css, "img.logo"
%WebDriver.Element{id: ":wdc:1373691496542", session: :test}
iex(13)> WebDriver.Session.element :test, :id, "branding"
%WebDriver.Element{id: ":wdc:1373691496543", session: :test}
Source
element(name, using, value, start_element)

Retreive an element from the page starting from the specified element using the specified search strategy.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/element

See WebDriver.Session.element/3 for details on search strategies.

Parameters: [using :: atom, value :: String, start_element :: WebDriver.Element.Reference]

Source
elements(name, using, value)

Retreive all elements from the page using the specified search strategy.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element

See element/3 for details on the parameters used. Returns a list of Element structs.

Source
elements(name, using, value, start_element)

Retreive all elements starting from the specified element using the specified search strategy.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/elements

See element/3 for details on the parameters used. The start_element parameter must be a WebDriver.Element struct. Returns a list of Element structs.

Source
execute(name, script, args \\ [])

Execute Javascript in the browser and return the result.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute

Example:

```

iex> WebDriver.Session.execute :test, "return 2+2;"
4
iex> WebDriver.Session.execute :test, "return arguments[0] * arguments[1];", [5,3]
15

```

Parameters: [script :: String, args :: List]

Returns: The Javascript return value, which may be a number,

string, list or object (map).
Source
execute_async(name, script, args \\ [])

Execute Javascript asynchronously in the browser and return the result.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute_async

Parameters: [script :: String, args :: List]

Returns: The Javascript return value, which may be a number,

string, list or object (map).
Source
forward(name)
Source
frame(name, id)

Change the frame that has focus in the current window. https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/frame

Parameters: %{id: string | number | :null | WebElement}

Source
javascript_enabled?(name)

True if javascript is enabled for this session

Source
keys(name, value)

Send a list of keystrokes to the currently active element. If you want to send non-printable keystrokes you must call Webdriver.Keys.key(key_symbol) to convert it properly.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/keys

Parameters: [ value :: String ]

Source
maximize_window(name, window_handle \\ "current")

Maximise the specified window. Use “current” or simply do not specify a handle to maximise the current window.

http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window/:windowHandle/maximize

Source
negotiated_capabilities(name)

Returns the negotiated capabilities of the current session.

Source
orientation(name)

Get the current browser screen orientation. Only works on browsers with the rotatable capability.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/orientation

Source
orientation(name, screen_orientation)

Set the current browser screen orientation https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/orientation

Parameters: [screen_orientation :: atom]

Screen orientaton can be either :portrait or :landscape.

Source
refresh(name)
Source
rotatable?(name)

True if this session supports device rotation.

Source
screenshot(name)

Get a PNG screenshot of the current page.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/screenshot

Returns: PngImage :: Binary

Source
session(name)

Get details about the current session on the WebDriver server.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId

Returns a capability record.

Source
sessions(name)

List all the sessions on the WebDriver browser.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId

Returns a list of session ids.

Source
set_async_script_timeout(name, ms)

Set the script timeout for the session.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts/async_script

Parameters: [ms :: number]

Source
set_cookie(name, cookie)

Set a cookie for the current page.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/cookie

Parameters: [cookie :: object]

Source
set_cookie(name, cookie_name, value, path, domain, expiry \\ in_one_hour())
Source
set_implicit_wait_timeout(name, ms)

Set the implicit wait timeout for the session.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/timeouts/implicit_wait

Parameters: [ms :: number]

Source
set_timeout(name, type, ms)

Set timeouts on the server. Parameters must include the type of timeout and the length in milliseconds (ms). Valid types are “script” and “implicit”

Parameters type: “script”|”implicit”, ms: number

Source
source(name)
Source
start_link(state, name)

Starts the session.

Source
start_session(name, desired_capabilities \\ %{})

Start a session with the desired capabilities on the browser. This is automatically called when the Session server starts, but in some cases you may want to stop and restart sessions without stopping and restarting the Session server.

Parameters:

name : The session server process to start the session on.
desired_capabilities: Capability
Source
status(name)

Returns the status of the WebDriver server.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/status

Source
stop(name)

Stop the session.

Source
stop_session(name)

Stop the session with the given name. Does not stop the Erlang server, just sends a request to the WebDriver server to stop the session.

Source
takes_screenshot?(name)

True if this session can take screenshots.

Source
url(name)
Source
url(name, url)

Navigate to the specified url.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#POST_/session/:sessionId/url

Note that this may take some time and calling other functions too soon may fail if the implicit wait is not set at a high enough value.

## Examples

iex> WebDriver.Session.url :session
"about:blank"
iex> WebDriver.Session.url :session, "http://www.google.com.au/"
iex> WebDriver.Session.url :session
"http://www.google.com.au/"

Parameters [url :: String]

Source
window(name, window_handle)

Change the focus to another window.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window

The window may be specified by the server assigned window handle or the value of it’s name attribute.

Parameters: %{window_handle : string}

Source
window_handle(name)

Get the handle of the current window. A window handle is an opaque reference used for various window related functions.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window_handle

Returns: window_handle :: String

Source
window_handles(name)

Get all the window handles associated with the browser. Returns a list of window handles.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window_handles

Returns: window_handles :: List[String]

Source
window_size(name)

Retreive the window size. If a window handle is not specified it retreives the current window.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#GET_/session/:sessionId/window/:windowHandle/size

Returns: %{height: number, width: number}

Source
window_size(name, window_handle, width, height)

Set the window size.

NOTE: Firefox can only do manipulation on the currently focussed window. You MUST pass the window_handle parameter as “current” for Firefox or you will get an error response.

https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window/:windowHandle/size

Parameters: [height :: number, width :: number]

Source