public class

SeleniumModule

extends Object
java.lang.Object
   ↳ org.mule.modules.selenium.SeleniumModule
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Selenium WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected. It aims to provide a friendly API that's easy to explore and understand, which will help make your tests easier to read and maintain.

Summary

Fields
private SeleniumWebDriver driver Web driver to use
private static Logger logger
private WebDriver webDriver Internal Selenium web driver
Public Constructors
SeleniumModule()
Public Methods
void clear(WebElement element)
If the element at the payload is a text entry element, this will clear the value.
void click(WebElement element)
Click the element at the payload.
void destroyDriver()
WebElement findElement(String id, String linkText, String partialLinkText, String name, String tagName, String xpathExpression, String className)
Find the first WebElement using the given method.
List<WebElement> findElements(String id, String linkText, String partialLinkText, String name, String tagName, String xpathExpression, String className)
Find all elements within the current page using the given mechanism.
void get(String url)
Load a new web page in the current browser window.
String getAttribute(WebElement element, String name)
Get the value of a the given attribute of the element.
String getCurrentUrl()
Get a string representing the current URL that the browser is looking at.
SeleniumWebDriver getDriver()
Point getLocation(WebElement element)
Where on the page is the top left-hand corner of the rendered element?

Dimension getSize(WebElement element)
What is the width and height of the rendered element?

String getTagName(WebElement element)
Get the tag name of this element.
String getText(WebElement element)
Get the visible (i.e.
String getTitle()
The title of the current page.
void initDriver()
boolean isDisplayed(WebElement element)
Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.
boolean isEnabled(WebElement element)
Is the element currently enabled or not? This will generally return true for everything but disabled input elements.
boolean isSelected(WebElement element)
Determine whether or not this element is selected or not.
void sendKeys(WebElement element, String keys)
Use this method to simulate typing into an element, which may set its value.
void setDriver(SeleniumWebDriver driver)
void submit(WebElement element)
If the element at the payload is a form, or an element within a form, then this will be submitted to the remote server.
void until(long timeOutInSeconds, NestedProcessor conditional)
Wait until the condition is successful

[Expand]
Inherited Methods
From class java.lang.Object

Fields

private SeleniumWebDriver driver

Web driver to use

private static Logger logger

private WebDriver webDriver

Internal Selenium web driver

Public Constructors

public SeleniumModule ()

Public Methods

public void clear (WebElement element)

If the element at the payload is a text entry element, this will clear the value. Has no effect on other elements. Text entry elements are INPUT and TEXTAREA elements.

Parameters
element Element located at the payload of the message

public void click (WebElement element)

Click the element at the payload. If this causes a new page to load, this method will block until the page has loaded. At this point, you should discard all references to this element and any further operations performed on this element will have undefined behaviour unless you know that the element and the page will still be present. If click() causes a new page to be loaded via an event or is done by sending a native event (which is a common case on Firefox, IE on Windows) then the method will *not* wait for it to be loaded and the caller should verify that a new page has been loaded.

If this element is not clickable, then this operation is a no-op since it's pretty common for someone to accidentally miss the target when clicking in Real Life

Parameters
element Element located at the payload of the message

public void destroyDriver ()

public WebElement findElement (String id, String linkText, String partialLinkText, String name, String tagName, String xpathExpression, String className)

Find the first WebElement using the given method. This method is affected by the 'implicit wait' times in force at the time of execution. The findElement(..) invocation will return a matching row, or try again repeatedly until the configured timeout is reached.

Parameters
id The value of the "id" attribute to search for
linkText The exact text to match against
partialLinkText The text to match against
name The value of the "name" attribute to search for
tagName The element's tagName
xpathExpression The xpath to use
className The value of the "class" attribute to search for * @return The first matching element on the current page
Returns
  • A singlel WebElement, or null if nothing matches
Throws
NoSuchElementException If no matching elements are found

public List<WebElement> findElements (String id, String linkText, String partialLinkText, String name, String tagName, String xpathExpression, String className)

Find all elements within the current page using the given mechanism. This method is affected by the 'implicit wait' times in force at the time of execution. When implicitly waiting, this method will return as soon as there are more than 0 items in the found collection, or will return an empty list if the timeout is reached.

Only one of the attributes can be used at any given time.

Parameters
id The value of the "id" attribute to search for
linkText The exact text to match against
partialLinkText The text to match against
name The value of the "name" attribute to search for
tagName The element's tagName
xpathExpression The xpath to use
className The value of the "class" attribute to search for
Returns
  • A list of all WebElements, or an empty list if nothing matches

public void get (String url)

Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page. Synonym for to(String).

Parameters
url The URL to load. It is best to use a fully qualified URL

public String getAttribute (WebElement element, String name)

Get the value of a the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded. More exactly, this method will return the value of the given attribute, unless that attribute is not present, in which case the value of the property with the same name is returned. If neither value is set, null is returned. The "style" attribute is converted as best can be to a text representation with a trailing semi-colon. The following are deemed to be "boolean" attributes, and will return either "true" or "false":

async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate

Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:

  • "class"
  • "readonly"

Parameters
element Element located at the payload of the message
name The name of the attribute.
Returns
  • The attribute's current value or null if the value is not set.

public String getCurrentUrl ()

Get a string representing the current URL that the browser is looking at.

Returns
  • The URL of the page currently loaded in the browser

public SeleniumWebDriver getDriver ()

public Point getLocation (WebElement element)

Where on the page is the top left-hand corner of the rendered element?

Parameters
element Element located at the payload of the message
Returns
  • A point, containing the location of the top left-hand corner of the element

public Dimension getSize (WebElement element)

What is the width and height of the rendered element?

Parameters
element Element located at the payload of the message
Returns
  • The size of the element on the page.

public String getTagName (WebElement element)

Get the tag name of this element. Not the value of the name attribute: will return "input" for the element <input name="foo" />.

Parameters
element
Returns
  • The tag name of this element.

public String getText (WebElement element)

Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements, without any leading or trailing whitespace.

Parameters
element Element located at the payload of the message
Returns
  • The innerText of this element.

public String getTitle ()

The title of the current page.

Returns
  • The title of the current page, with leading and trailing whitespace stripped, or null if one is not already set

public void initDriver ()

Throws
IllegalAccessException
InstantiationException

public boolean isDisplayed (WebElement element)

Is this element displayed or not? This method avoids the problem of having to parse an element's "style" attribute.

Parameters
element Element located at the payload of the message
Returns
  • Whether or not the element is displayed

public boolean isEnabled (WebElement element)

Is the element currently enabled or not? This will generally return true for everything but disabled input elements.

Parameters
element Element located at the payload of the message
Returns
  • True if the element is enabled, false otherwise.

public boolean isSelected (WebElement element)

Determine whether or not this element is selected or not. This operation only applies to input elements such as checkboxes, options in a select and radio buttons.

Parameters
element Element located at the payload of the message
Returns
  • True if the element is currently selected or checked, false otherwise.

public void sendKeys (WebElement element, String keys)

Use this method to simulate typing into an element, which may set its value. The payload must be of type WebElement

Parameters
element Element located at the payload of the message
keys Keys to send

public void setDriver (SeleniumWebDriver driver)

Parameters
driver

public void submit (WebElement element)

If the element at the payload is a form, or an element within a form, then this will be submitted to the remote server. If this causes the current page to change, then this method will block until the new page is loaded.

Parameters
element Element located at the payload of the message
Throws
java.util.NoSuchElementException} If the given element is not within a form

public void until (long timeOutInSeconds, NestedProcessor conditional)

Wait until the condition is successful

Parameters
timeOutInSeconds The timeout in seconds when an expectation is called
conditional Nested processor to be executed for evaluating conditions