Canoo Webtest WebTest Canoo

Extension Step clickElement


Clicks an HTML element identified by its id or xpath. If the click triggers the load of a new page, then this page becomes the current one.


Required? no
The description of this test step.
Required? yes/no
The id of the html element to click on. One of htmlId or xPath must be set.
Required? no
A password that can be provided for pages that require basic authentication. Required if username is specified.
Required? no
A shorthand: save='prefixName' is the same as savePrefix='prefixName' saveResponse='true'.
Required? no, default is the 'savePrefix' parameter as specified in <config>.
A name prefix can be specified for making a permanent copy of received responses. A unique number and the file extension (depending on the MIME-Type) will be appended. The resultpath attribute of the <config> element is used for determining the location of the saved result.
Required? no
Whether to make a permanent copy of received responses. Overrides the default value set in the <config> element.
Required? no
A username that can be provided for pages that require basic authentication. Typically only needed on the first step of any webtest accessing a secure site. Required if password is specified.
Required? yes/no
The XPath identifying the html element to click on. One of htmlId or xPath must be set.


Consider the following HTML page:

clickElement HTML
<script type="text/JavaScript">
function flipColor(obj) {
  var color=( ? "yellow" :;;
// -->
<table cellspacing="1border="1">
    <tr style="backgroundColor:red;background:redid="redonclick="flipColor(this)">
        <td width="150height="30"></td><td width="150"></td><td width="150"></td>
    <tr style="backgroundColor:green;background:greenid="greenonclick="flipColor(this)">
        <td width="150height="30"></td><td width="150"></td><td width="150"></td>
    <tr style="backgroundColor:blue;background:blueid="blueonclick="flipColor(this)">
        <td width="150height="30"></td><td width="150"></td><td width="150"></td>

The page contains no links or buttons but we want to be able to activate and check the onclick JavaScript. We can do this using the <clickElement> step as follows:

clickElement Example
<webtest name="clickElement: Click Table Cell">
  <config ... />
        <invoke description="starturl="colorChange.html"/>
        <-- first row tests -->
        <storeElementAttribute htmlId="redattributeName="stylepropertyName="colorBefore1"/>
        <verifyProperty name="colorBefore1text=".*backgroundColor:[ ]*red.*regex="true"/>
        <clickElement description="toggle color of first rowhtmlId="red"/>
        <storeElementAttribute htmlId="redattributeName="stylepropertyName="colorAfter1"/>
        <verifyProperty name="colorAfter1text=".*backgroundColor:[ ]*yellow.*regex="true"/>
        <clickElement description="toggle color of first row backhtmlId="red"/>
        <storeElementAttribute htmlId="redattributeName="stylepropertyName="colorFinal1"/>
        <verifyProperty name="colorFinal1text=".*backgroundColor:[ ]*red.*regex="true"/>
        <-- second row tests -->
        <storeElementAttribute xpath="//tr[2]attributeName="stylepropertyName="colorBefore2"/>
        <verifyProperty name="colorBefore2text=".*backgroundColor:[ ]*green.*regex="true"/>
        <clickElement description="toggle color of second rowxpath="//tr[2]"/>
        <storeElementAttribute xpath="//tr[2]attributeName="stylepropertyName="colorAfter2"/>
        <verifyProperty name="colorAfter2text=".*backgroundColor:[ ]*yellow.*regex="true"/>

See also: the storeElementAttribute step.


Latest build: development
Posted: 19-Jul-2016 17:36

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007