This class supports switching to the currently active element in ScalaTest's Selenium DSL.
This class supports switching to the alert box in ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
A class name query.
This class is part of ScalaTest's Selenium DSL.
This class is part of the ScalaTest's Selenium DSL.
A CSS selector query.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class supports switching to the default content in ScalaTest's Selenium DSL.
A dimension containing the width and height of a screen element.
Wrapper class for a Selenium WebElement
.
This class is part of ScalaTest's Selenium DSL.
This class supports switching to a frame by element in ScalaTest's Selenium DSL.
This class supports switching to a frame by index in ScalaTest's Selenium DSL.
This class supports switching to a frame by name or ID in ScalaTest's Selenium DSL.
This class supports switching to a frame by web element in ScalaTest's Selenium DSL.
An ID query.
A link text query.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
A name query.
This class is part of ScalaTest's Selenium DSL.
Trait that facilitates using the page object pattern with the ScalaTest Selenium DSL.
A partial link text query.
This class is part of ScalaTest's Selenium DSL.
A point containing an XY screen location.
This trait is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This sealed abstract class supports switching in ScalaTest's Selenium DSL.
A tag name query.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class is part of ScalaTest's Selenium DSL.
This class supports switching to a window by name or handle in ScalaTest's Selenium DSL.
Wrapper class for a Selenium Cookie
.
An XPath query.
This value supports switching to the currently active element in ScalaTest's Selenium DSL.
This value supports switching to the currently active element in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
This class is enables the following syntax:
switch to activeElement ^
This object is part of ScalaTest's Selenium DSL.
Add cookie in the web browser.
Add cookie in the web browser. If the cookie's domain name is left blank (default), it is assumed that the cookie is meant for the domain of the current document.
cookie's name
cookie's value
cookie's path
cookie's expiry data
cookie's domain name
whether this cookie is secured.
the WebDriver
with which to drive the browser
This value supports switching to the alert box in ScalaTest's Selenium DSL.
This value supports switching to the alert box in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
This class is enables the following syntax:
switch to alertBox ^
This object is part of ScalaTest's Selenium DSL.
Capture screenshot and save it as the specified name (if file name does not end with .
Capture screenshot and save it as the specified name (if file name does not end with .png, it will be extended automatically) in capture directory,
which by default is system property's java.io.tmpdir. You can change capture directory by calling setCaptureDir
screenshot file name, if does not end with .png, it will be extended automatically
Finds and returns the first Checkbox
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a Checkbox
.
Finds and returns the first Checkbox
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a Checkbox
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the Checkbox
selected by this query
if element not found or found element is not a Checkbox
Finds and returns the first Checkbox
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a Checkbox
.
Finds and returns the first Checkbox
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a Checkbox
.
the Query
with which to search
the WebDriver
with which to drive the browser
the Checkbox
selected by this query
if element not found or found element is not a Checkbox
Returns a class name query.
Returns a class name query.
This method enables syntax such as the following:
click on className("???")
^
This object is part of ScalaTest's Selenium DSL.
Click on the specified Element
Click on the specified Element
the Element
to click on
Click on the first Element
selected by the specified string ID or name
Click on the first Element
selected by the specified string ID or name
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
Click on the first Element
selected by the specified Query
Click on the first Element
selected by the specified Query
the Query
with which to search
the WebDriver
with which to drive the browser
Click on the specified WebElement
Click on the specified WebElement
the WebElement
to click on
Closes the current browser window, and exits the driver if the current window was the only one remaining.
Closes the current browser window, and exits the driver if the current window was the only one remaining.
the WebDriver
with which to drive the browser
Finds and returns the first ColorField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a ColorField
.
Finds and returns the first ColorField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a ColorField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the ColorField
selected by this query
if element not found or found element is not a ColorField
Finds and returns the first ColorField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a ColorField
.
Finds and returns the first ColorField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a ColorField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the ColorField
selected by this query
if element not found or found element is not a ColorField
Get a saved cookie from web browser, throws TestFailedException if the cookie does not exist.
Get a saved cookie from web browser, throws TestFailedException if the cookie does not exist.
cookie's name
a WrappedCookie instance
This field supports cookie deletion in ScalaTest's Selenium DSL.
This field supports cookie deletion in ScalaTest's Selenium DSL. Please see the documentation for
WebBrowser
for an overview of the Selenium DSL.
This field enables the following syntax:
delete all cookies ^
Returns a CSS selector query.
Returns a CSS selector query.
This method enables syntax such as the following:
click on cssSelector("???")
^
Returns the URL of the current page.
Returns the URL of the current page.
This method invokes getCurrentUrl
on the passed WebDriver
and returns the result.
the WebDriver
with which to drive the browser
the URL of the current page
Finds and returns the first DateField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a DateField
.
Finds and returns the first DateField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a DateField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the DateField
selected by this query
if element not found or found element is not a DateField
Finds and returns the first DateField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a DateField
.
Finds and returns the first DateField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a DateField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the DateField
selected by this query
if element not found or found element is not a DateField
Finds and returns the first DateTimeField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a DateTimeField
.
Finds and returns the first DateTimeField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a DateTimeField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the DateTimeField
selected by this query
if element not found or found element is not a DateTimeField
Finds and returns the first DateTimeField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a DateTimeField
.
Finds and returns the first DateTimeField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a DateTimeField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the DateTimeField
selected by this query
if element not found or found element is not a DateTimeField
Finds and returns the first DateTimeLocalField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a DateTimeLocalField
.
Finds and returns the first DateTimeLocalField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a DateTimeLocalField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the DateTimeLocalField
selected by this query
if element not found or found element is not a DateTimeLocalField
Finds and returns the first DateTimeLocalField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a DateTimeLocalField
.
Finds and returns the first DateTimeLocalField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a DateTimeLocalField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the DateTimeLocalField
selected by this query
if element not found or found element is not a DateTimeLocalField
This value supports switching to the default content in ScalaTest's Selenium DSL.
This value supports switching to the default content in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
This class is enables the following syntax:
switch to defaultContent ^
This object is part of ScalaTest's Selenium DSL.
Delete all cookies in the current domain from web browser.
Delete all cookies in the current domain from web browser.
the WebDriver
with which to drive the browser
Delete cookie with the specified name from web browser, throws TestFailedException if the specified cookie does not exists.
Delete cookie with the specified name from web browser, throws TestFailedException if the specified cookie does not exists.
cookie's name
the WebDriver
with which to drive the browser
Finds and returns the first EmailField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a EmailField
.
Finds and returns the first EmailField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a EmailField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the EmailField
selected by this query
if element not found or found element is not a EmailField
Finds and returns the first EmailField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a EmailField
.
Finds and returns the first EmailField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a EmailField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the EmailField
selected by this query
if element not found or found element is not a EmailField
Clears the current active TextField
or TextArea
, and presses the passed keys.
Clears the current active TextField
or TextArea
, and presses the passed keys.
Throws TestFailedException
if current active is not TextField
or TextArea
.
keys to press in current active TextField
or TextArea
Executes an asynchronous piece of JavaScript in the context of the currently selected frame or window.
Executes an asynchronous piece of JavaScript in the context of the currently selected frame or window. Unlike executing synchronous JavaScript, scripts executed with this method must explicitly signal they are finished by invoking the provided callback. This callback is always injected into the executed function as the last argument.
The first argument passed to the callback function will be used as the script's result. This value will be handled as follows:
Script arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" variable.
the JavaScript to execute
the arguments to the script, may be empty
One of Boolean, Long, String, List, WebElement, or null
Executes JavaScript in the context of the currently selected frame or window.
Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.
Within the script, you can use document
to refer to the current document. Local variables will not be available once the script has finished executing, but global variables will.
To return a value (e.g. if the script contains a return statement), then the following steps will be taken:
the JavaScript to execute
the arguments to the script, may be empty
One of Boolean, Long, String, List or WebElement. Or null
Finds and returns the first element selected by the specified string ID or name, wrapped
in a Some
, or None
if no element is selected.
Finds and returns the first element selected by the specified string ID or name, wrapped
in a Some
, or None
if no element is selected. YYY
This method will try to lookup by id first. If it cannot find
any element with an id equal to the specified queryString
, it will then try lookup by name.
The class of the Element
returned will be a subtype of Element
if appropriate.
For example, if the query selects a text field, the class of the returned Element
will
be TextField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the Element
selected by this query, wrapped in a Some
, or None
if
no Element
is selected
Finds and returns the first element selected by the specified Query
, wrapped
in a Some
, or None
if no element is selected.
Finds and returns the first element selected by the specified Query
, wrapped
in a Some
, or None
if no element is selected.
The class of the Element
returned will be a subtype of Element
if appropriate.
For example, if the query selects a text field, the class of the returned Element
will
be TextField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the Element
selected by this query, wrapped in a Some
, or None
if
no Element
is selected
Returns an Iterator
over all Element
s selected by the specified string ID or name
Returns an Iterator
over all Element
s selected by the specified string ID or name
This method will try to lookup by id first. If it cannot find
any element with an id equal to the specified queryString
, it will then try lookup by name.
The class of the Element
returned will be a subtype of Element
if appropriate.
For example, if the query selects a text field, the class of the returned Element
will
be TextField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the Iterator
over all Element
s selected by this query
Returns an Iterator
over all Element
s selected by this query.
Returns an Iterator
over all Element
s selected by this query.
The class of the Element
s produced by the returned Iterator
will be a
subtypes of Element
if appropriate. For example, if an Element
representing
a text field is returned by the Iterator
, the class of the returned Element
will
be TextField
.
If no Elements
are selected by this query, this method will return an empty Iterator
will be returned.
the Query
with which to search
the WebDriver
with which to drive the browser
the Iterator
over all Element
s selected by this query
This method supports switching to a frame by Query
in ScalaTest's Selenium DSL.
This method supports switching to a frame by Query
in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
Query
used to select WebElement
which is contained in the frame to switch to
a FrameWebElementTarget instance
This method supports switching to a frame by element in ScalaTest's Selenium DSL.
This method supports switching to a frame by element in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
Element
which is contained in the frame to switch to
a FrameElementTarget instance
This method supports switching to a frame by web element in ScalaTest's Selenium DSL.
This method supports switching to a frame by web element in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
WebElement
which is contained in the frame to switch to
a FrameWebElementTarget instance
This method supports switching to a frame by name or ID in ScalaTest's Selenium DSL.
This method supports switching to a frame by name or ID in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
This class is enables the following syntax:
switch to frame("name") ^
name or ID of the frame to switch to
a FrameNameOrIdTarget instance
This method supports switching to a frame by index in ScalaTest's Selenium DSL.
This method supports switching to a frame by index in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
This class is enables the following syntax:
switch to frame(0) ^
the index of frame to switch to
a FrameIndexTarget instance
This object is part of ScalaTest's Selenium DSL.
Go back to previous page.
Go back to previous page.
the WebDriver
with which to drive the browser
Go forward to next page.
Go forward to next page.
the WebDriver
with which to drive the browser
Sends the browser to the URL contained in the passed Page
object.
Sends the browser to the URL contained in the passed Page
object.
Here's an example:
goTo(homePage)
the Page
object containing the URL to which to send the browser
the WebDriver
with which to drive the browser
Sends the browser to the passed URL.
Sends the browser to the passed URL.
Here's an example:
goTo("http://www.artima.com")
the URL to which to send the browser
the WebDriver
with which to drive the browser
Returns an ID query.
Returns an ID query.
This method enables syntax such as the following:
click on id("q")
^
Sets the amount of time the driver should wait when searching for an element that is not immediately present.
Sets the amount of time the driver should wait when searching for an element that is not immediately present.
When searching for requested elements, Selenium will poll the page until the requested element (or at least one of multiple requested
elements) is found or this "implicit wait" timeout has expired.
If the timeout expires, Selenium will throw NoSuchElementException
, which ScalaTest's Selenium DSL will wrap in a TestFailedException
.
You can alternatively set this timeout to zero and use ScalaTest's eventually
construct.
This method invokes manage.timeouts.implicitlyWait
on the passed WebDriver
. See the documentation of Selenium's
WebDriver#Timeouts
interface for more information.
the time span to implicitly wait
the WebDriver
on which to set the implicit wait
Check if screenshot is supported
Check if screenshot is supported
the WebDriver
with which to drive the browser
true if screenshot is supported, false otherwise
Returns a link text query.
Returns a link text query.
This method enables syntax such as the following:
click on linkText("???")
^
Finds and returns the first MonthField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a MonthField
.
Finds and returns the first MonthField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a MonthField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the MonthField
selected by this query
if element not found or found element is not a MonthField
Finds and returns the first MonthField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a MonthField
.
Finds and returns the first MonthField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a MonthField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the MonthField
selected by this query
if element not found or found element is not a MonthField
Finds and returns the first MultiSel
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a MultiSel
.
Finds and returns the first MultiSel
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a MultiSel
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the MultiSel
selected by this query
if element not found or found element is not a MultiSel
Finds and returns the first MultiSel
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a MultiSel
.
Finds and returns the first MultiSel
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a MultiSel
.
the Query
with which to search
the WebDriver
with which to drive the browser
the MultiSel
selected by this query
if element not found or found element is not a MultiSel
Returns a name query.
Returns a name query.
This method enables syntax such as the following:
click on name("q")
^
Finds and returns the first NumberField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a NumberField
.
Finds and returns the first NumberField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a NumberField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the NumberField
selected by this query
if element not found or found element is not a NumberField
Finds and returns the first NumberField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a NumberField
.
Finds and returns the first NumberField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a NumberField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the NumberField
selected by this query
if element not found or found element is not a NumberField
Returns the source of the current page.
Returns the source of the current page.
This method invokes getPageSource
on the passed WebDriver
and returns the result.
the WebDriver
with which to drive the browser
the source of the current page
Returns the title of the current page, or the empty string if the current page has no title.
Returns the title of the current page, or the empty string if the current page has no title.
the WebDriver
with which to drive the browser
the current page's title, or the empty string if the current page has no title
Returns a partial link text query.
Returns a partial link text query.
This method enables syntax such as the following:
click on partialLinkText("???")
^
Press the passed keys to current active element.
Press the passed keys to current active element.
keys to press in current active element
Finds and returns the first PasswordField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a PasswordField
.
Finds and returns the first PasswordField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a PasswordField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the PasswordField
selected by this query
if element not found or found element is not a PasswordField
Finds and returns the first PasswordField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a PasswordField
.
Finds and returns the first PasswordField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a PasswordField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the PasswordField
selected by this query
if element not found or found element is not a PasswordField
Close all windows, and exit the driver.
Close all windows, and exit the driver.
the WebDriver
on which to quit.
Finds and returns the first RadioButton
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a RadioButton
.
Finds and returns the first RadioButton
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a RadioButton
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the RadioButton
selected by this query
if element not found or found element is not a RadioButton
Finds and returns the first RadioButton
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a RadioButton
.
Finds and returns the first RadioButton
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a RadioButton
.
the Query
with which to search
the WebDriver
with which to drive the browser
the RadioButton
selected by this query
if element not found or found element is not a RadioButton
Finds and returns RadioButtonGroup
selected by the specified group name, throws TestFailedException
if
no element with the specified group name is found, or found any element with the specified group name but not a RadioButton
Finds and returns RadioButtonGroup
selected by the specified group name, throws TestFailedException
if
no element with the specified group name is found, or found any element with the specified group name but not a RadioButton
the group name with which to search
the WebDriver
with which to drive the browser
the RadioButtonGroup
selected by this query
if no element with the specified group name is found, or found any element with the specified group name but not a RadioButton
Finds and returns the first RangeField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a RangeField
.
Finds and returns the first RangeField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a RangeField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the RangeField
selected by this query
if element not found or found element is not a RangeField
Finds and returns the first RangeField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a RangeField
.
Finds and returns the first RangeField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a RangeField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the RangeField
selected by this query
if element not found or found element is not a RangeField
Reload the current page.
Reload the current page.
the WebDriver
with which to drive the browser
Finds and returns the first SearchField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a SearchField
.
Finds and returns the first SearchField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a SearchField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the SearchField
selected by this query
if element not found or found element is not a SearchField
Finds and returns the first SearchField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a SearchField
.
Finds and returns the first SearchField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a SearchField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the SearchField
selected by this query
if element not found or found element is not a SearchField
Set capture directory.
Set capture directory.
the path of capture directory
Sets the amount of time to wait for an asynchronous script to finish execution before throwing an exception.
Sets the amount of time to wait for an asynchronous script to finish execution before throwing an exception.
the amount of time to wait for an asynchronous script to finish execution before throwing exception
Finds and returns the first SingleSel
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a SingleSel
.
Finds and returns the first SingleSel
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a SingleSel
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the SingleSel
selected by this query
if element not found or found element is not a SingleSel
Finds and returns the first SingleSel
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a SingleSel
.
Finds and returns the first SingleSel
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a SingleSel
.
the Query
with which to search
the WebDriver
with which to drive the browser
the SingleSel
selected by this query
if element not found or found element is not a SingleSel
Submit the form where current active element belongs to, and throws TestFailedException if current active element is not in a form or underlying WebDriver encounters problem when submitting the form.
Submit the form where current active element belongs to, and throws TestFailedException if current active element is not in a form or underlying WebDriver encounters problem when submitting the form. If this causes the current page to change, this call will block until the new page is loaded.
the WebDriver
with which to drive the browser
if current active element is not in a form or underlying WebDriver encounters problem when submitting the form.
This object is part of ScalaTest's Selenium DSL.
Switch to the specified SwitchTarget
Switch to the specified SwitchTarget
the SwitchTarget
to switch to
the WebDriver
with which to drive the browser
instance of specified SwitchTarget
's type parameter
Returns a tag name query.
Returns a tag name query.
This method enables syntax such as the following:
click on tagName("???")
^
Finds and returns the first TelField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TelField
.
Finds and returns the first TelField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TelField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the TelField
selected by this query
if element not found or found element is not a TelField
Finds and returns the first TelField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TelField
.
Finds and returns the first TelField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TelField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the TelField
selected by this query
if element not found or found element is not a TelField
Finds and returns the first TextArea
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TextArea
.
Finds and returns the first TextArea
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TextArea
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the TextArea
selected by this query
if element not found or found element is not a TextArea
Finds and returns the first TextArea
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TextArea
.
Finds and returns the first TextArea
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TextArea
.
the Query
with which to search
the WebDriver
with which to drive the browser
the TextArea
selected by this query
if element not found or found element is not a TextArea
Finds and returns the first TextField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TextField
.
Finds and returns the first TextField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TextField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the TextField
selected by this query
if element not found or found element is not a TextField
Finds and returns the first TextField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TextField
.
Finds and returns the first TextField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TextField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the TextField
selected by this query
if element not found or found element is not a TextField
Finds and returns the first TimeField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TimeField
.
Finds and returns the first TimeField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a TimeField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the TimeField
selected by this query
if element not found or found element is not a TimeField
Finds and returns the first TimeField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TimeField
.
Finds and returns the first TimeField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a TimeField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the TimeField
selected by this query
if element not found or found element is not a TimeField
Finds and returns the first UrlField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a UrlField
.
Finds and returns the first UrlField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a UrlField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the UrlField
selected by this query
if element not found or found element is not a UrlField
Finds and returns the first UrlField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a UrlField
.
Finds and returns the first UrlField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a UrlField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the UrlField
selected by this query
if element not found or found element is not a UrlField
Finds and returns the first WeekField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a WeekField
.
Finds and returns the first WeekField
selected by the specified string ID or name, throws TestFailedException
if element not found or the found element is not a WeekField
.
the string with which to search, first by ID then by name
the WebDriver
with which to drive the browser
the WeekField
selected by this query
if element not found or found element is not a WeekField
Finds and returns the first WeekField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a WeekField
.
Finds and returns the first WeekField
selected by the specified Query
, throws TestFailedException
if element not found or the found element is not a WeekField
.
the Query
with which to search
the WebDriver
with which to drive the browser
the WeekField
selected by this query
if element not found or found element is not a WeekField
This class supports switching to a window by name or handle in ScalaTest's Selenium DSL.
This class supports switching to a window by name or handle in ScalaTest's Selenium DSL.
Please see the documentation for WebBrowser
for an overview of the Selenium DSL.
This class is enables the following syntax:
switch to window(windowHandle) ^
name or window handle of the window to switch to
a WindowTarget instance
Get an opaque handle to current active window that uniquely identifies it within the implicit driver instance.
Get an opaque handle to current active window that uniquely identifies it within the implicit driver instance.
the WebDriver
with which to drive the browser
Get a set of window handles which can be used to iterate over all open windows
Get a set of window handles which can be used to iterate over all open windows
the WebDriver
with which to drive the browser
Execute the given function, if ModifiableMessage
exception is thrown from the given function,
a screenshot will be captured automatically into capture directory, which by default is system property's java.
Execute the given function, if ModifiableMessage
exception is thrown from the given function,
a screenshot will be captured automatically into capture directory, which by default is system property's java.io.tmpdir.
You can change capture directory by calling setCaptureDir
function to execute
Returns an XPath query.
Returns an XPath query.
This method enables syntax such as the following:
click on xpath("???")
^
Trait that provides a domain specific language (DSL) for writing browser-based tests using Selenium.
To use ScalaTest's Selenium DSL, mix trait
WebBrowser
into your test class. This trait provides the DSL in its entirety except for one missing piece: an implicitorg.openqa.selenium.WebDriver
. One way to provide the missing implicit driver is to declare one as a member of your test class, like this:For convenience, however, ScalaTest provides a
WebBrowser
subtrait containing an implicitWebDriver
for each driver provided by Selenium. Thus a simpler way to use theHtmlUnit
driver, for example, is to extend ScalaTest'sHtmlUnit
trait, like this:The web driver traits provided by ScalaTest are:
WebBrowser
subtraitChrome
Firefox
HtmlUnit
InternetExplorer
Safari
Navigation
You can ask the browser to retrieve a page (go to a URL) like this:
go to "http://www.artima.com"
Note: If you are using the page object pattern, you can also go to a page using the
Page
instance, as illustrated in the section on page objects below.Once you have retrieved a page, you can fill in and submit forms, query for the values of page elements, and make assertions. In the following example, selenium will go to
http://www.google.com
, fill in the text box withCheese!
, press the submit button, and wait for result returned from an AJAX call:In the above example, the
"q"
used in “click on "q"
” can be either the id or name of an element. ScalaTest's Selenium DSL will try to lookup by id first. If it cannot find any element with an id equal to"q"
, it will then try lookup by name"q"
.Alternatively, you can be more specific:
In addition to
id
andname
, you can use the following approaches to lookup elements, just as you can do with Selenium'sorg.openqa.selenium.By
class:xpath
className
cssSelector
linkText
partialLinkText
tagName
For example, you can select by link text with:
click on linkText("click here!")
If an element is not found via any form of lookup, evaluation will complete abruptly with a
TestFailedException
.Getting and setting input element values
ScalaTest's Selenium DSL provides a clear, simple syntax for accessing and updating the values of input elements such as text fields, radio buttons, checkboxes, selection lists, and the input types introduced in HTML5. If a requested element is not found, or if it is found but is not of the requested type, an exception will immediately result causing the test to fail.
The most common way to access field value is through the
value
property, which is supported by the following input types:input
text
textField
textarea
-
textArea
input
password
pwdField
input
email
emailField
input
color
colorField
input
date
dateField
input
datetime
dateTimeField
input
datetime-local
dateTimeLocalField
input
month
monthField
input
number
numberField
input
range
rangeField
input
search
searchField
input
tel
telField
input
time
timeField
input
url
urlField
input
week
weekField
You can change a input field's value by assigning it via the
=
operator, like this:And you can access a input field's value by simply invoking
value
on it:If the text field is empty,
value
will return an empty string (""
).You can use the same syntax with other type of input fields by replacing
textField
withLookup Method
listed in table above, for example to use text area:or with a password field:
Alternate Way for Data Entry
An alternate way to enter data into a input fields is to use
enter
orpressKeys
. Although both ofenter
andpressKeys
send characters to the active element,pressKeys
can be used on any kind of element, whereasenter
can only be used on text entry fields, which include:textField
textArea
pwdField
emailField
searchField
telField
urlField
Another difference is that
enter
will clear the text field or area before sending the characters, effectively replacing any currently existing text with the new text passed toenter
. By contrast,pressKeys
does not do any clearing—it just appends more characters to any existing text. You can backup withpressKeys
, however, by sending explicit backspace characters,"\u0008"
.To use these commands, you must first click on the input field you are interested in to give it the focus. Here's an example:
Here's a (contrived) example of using
pressKeys
with backspace to fix a typo:Radio buttons
Radio buttons work together in groups. For example, you could have a group of radio buttons, like this:
You can select an option in either of two ways:
Likewise, you can read the currently selected value of a group of radio buttons in two ways:
If the radio button has no selection at all,
selection
will returnNone
whereasvalue
will throw aTestFailedException
. By usingvalue
, you are indicating you expect a selection, and if there isn't a selection that should result in a failed test.If you would like to work with
RadioButton
element directly, you can select it by callingradioButton
:click on radioButton("opt1")
you can check if an option is selected by calling
isSelected
:to get the value of radio button, you can call
value
:Checkboxes
A checkbox in one of two states: selected or cleared. Here's how you select a checkbox:
checkbox("cbx1").select()
And here's how you'd clear one:
checkbox("cbx1").clear()
You can access the current state of a checkbox with
isSelected
:Single-selection dropdown lists
Given the following single-selection dropdown list:
You could select
Option 2
in either of two ways:To clear the selection, either invoke
clear
or setselection
toNone
:You can read the currently selected value of a single-selection list in the same manner as radio buttons:
If the single-selection list has no selection at all,
selection
will returnNone
whereasvalue
will throw aTestFailedException
. By usingvalue
, you are indicating you expect a selection, and if there isn't a selection that should result in a failed test.Multiple-selection lists
Given the following multiple-selection list:
You could select
Option 5
andOption 6
like this:The previous command would essentially clear all selections first, then select
Option 5
andOption 6
. If instead you want to not clear any existing selection, just additionally selectOption 5
andOption 6
, you can use the+=
operator, like this.To clear a specific option, pass its name to
clear
:To clear all selections, call
clearAll
:multiSel("select2").clearAll()
You can access the current selections with
values
, which returns an immutableIndexedSeq[String]
:Clicking and submitting
You can click on any element with “
click on
” as shown previously:If the requested element is not found,
click on
will throw an exception, failing the test.Clicking on a input element will give it the focus. If current focus is in on an input element within a form, you can submit the form by calling
submit
:Switching
You can switch to a popup alert bo using the following code:
to switch to a frame, you could:
If you have reference to a window handle (can be obtained from calling windowHandle/windowHandles), you can switch to a particular window by:
You can also switch to active element and default content:
Navigation history
In real web browser, you can press the 'Back' button to go back to previous page. To emulate that action in your test, you can call
goBack
:To emulate the 'Forward' button, you can call:
And to refresh or reload the current page, you can call:
Cookies!
To create a new cookie, you'll say:
to read a cookie value, you do:
In addition to the common use of name-value cookie, you can pass these extra fields when creating the cookie, available ways are:
and to read those extra fields:
In order to delete a cookie, you could use the following code:
delete cookie "cookie_name"
or to delete all cookies in the same domain:-
To get the underlying Selenium cookie, you can use
underlying
:Other useful element properties
All element types (
textField
,textArea
,radioButton
,checkbox
,singleSel
,multiSel
) support the following useful properties:location
Element
.size
Element
.isDisplayed
Element
is displayed.isEnabled
Element
is enabled.isSelected
Element
is selected.tagName
underlying
WebElement
wrapped by thisElement
.attribute(name: String)
Some
, orNone
if no such attribute exists on thisElement
.text
Implicit wait
To set Selenium's implicit wait timeout, you can call the
implicitlyWait
method:Invoking this method sets the amount of time the driver will wait when searching for an element that is not immediately present. For more information, see the documentation for method
implicitlyWait
.Page source and current URL
It is possible to get the html source of currently loaded page, using:
and if needed, get the current URL of currently loaded page:
Screen capture
You can capture screen using the following code:
val file = capture
By default, the captured image file will be saved in temporary folder (returned by java.io.tmpdir property), with random file name ends with .png extension. You can specify a fixed file name:
capture to "MyScreenShot.png"
or
capture to "MyScreenShot"
Both will result in a same file name
MyScreenShot.png
.You can also change the target folder screenshot file is written to, by saying:
setCaptureDir("/home/your_name/screenshots")
If you want to capture a screenshot when something goes wrong (e.g. test failed), you can use
withScreenshot
:In case the test code fails, you'll see the screenshot location appended to the error message, for example:
Expected gold but got silver; screenshot capture in /tmp/AbCdEfGhIj.png
Using the page object pattern
If you use the page object pattern, mixing trait
Page
into your page classes will allow you to use thego to
syntax with your page objects. Here's an example:Executing JavaScript
To execute arbitrary JavaScript, for example, to test some JavaScript functions on your page, pass it to
executeScript
:To execute an asynchronous bit of JavaScript, pass it to
executeAsyncScript
. You can set the script timeout withsetScriptTimeout
:Querying for elements
You can query for arbitrary elements via
find
andfindAll
. Thefind
method returns the first matching element, wrapped in aSome
, orNone
if no element is found. ThefindAll
method returns an immutableIndexedSeq
of all matching elements. If no elements match the query,findAll
returns an emptyIndexedSeq
. These methods allow you to perform rich queries usingfor
expressions. Here are some examples:Cleaning up
To close the current browser window, and exit the driver if the current window was the only one remaining, use
close
:To close all windows, and exit the driver, use
quit
:Alternate forms
Although statements like “
delete all cookies
” fit well with matcher statements like “title should be ("Cheese!")
”, they do not fit as well with the simple method call form of assertions. If you prefer, you can avoid operator notation and instead use alternatives that take the form of plain-old method calls. Here's an example:Here's a table showing the complete list of alternatives:
go to (host + "index.html")
goTo(host + "index.html")
click on "aButton"
clickOn("aButton")
switch to activeElement
switchTo(activeElement)
add cookie ("cookie_name", "cookie_value")
addCookie("cookie_name", "cookie_value")
delete cookie "cookie_name"
deleteCookie("cookie_name")
delete all cookies
deleteAllCookies()
capture to "MyScreenShot"
captureTo("MyScreenShot")