Wiki
Clone wikiScripted Selenium / Commands
Overview
This section defines the various commands that can be used to interact with a web application. The commands move the mouse to a target location. Commands that are not recognized by the script interpreter are ignored; see the Reserved Commands for plans on future directions.
Target selectors can be specified using id
, css
, or xpath
attributes.
Visit
Use visit
to direct the browser to a web site. This should be the first command.
Example
#!xml <visit>http://bitbucket.org</visit>
Cookie
Use cookie
to set a client-side cookie. This is only permitted after a <visit />
command.
Example
#!xml <cookie name="monster">123ABC</cookie>
Click
Use click
for a left-button mouse press.
Examples
Click using a default delay:
#!xml <click id="id-attribute" />
Click using a default delay of 2.5 seconds, and for every subsequent click (until the delay is explicitly changed again):
#!xml <click id="html-element-id" delay="2500" />
Click an anchor link based on its text:
#!xml <click link="link-text" />
Text
Use text
for data entry of input fields, textareas, and contenteditable elements.
Examples
Click and add text to an input field:
#!xml <text css="css-selector">Text example</text>
Click and add escaped text to an input field (e.g., a textarea):
#!xml <text css="css-selector"><![CDATA[ <text css="css-selector">Self-Referential Text & Ampersands</text> ]]></text>
Click and add text to contentEditable, set the edit
attribute to true
:
#!xml <text css="css-selector" edit="true">Text example</text>
To upload a file, set the click
attribute to false
and provide the file's full path:
#!xml <text id="upload-element-id" click="false">/path/to/file.txt</text>
Option
Use option
to choose a value by its text from a drop-down or multi-select list.
Example
#!xml <option text="displayed-value" />
Frame
Use frame
to switch to an iframe element, selected using its index. The first iframe on the page is at index 0.
Example
Add text to a contentEditable area inside an HTML iframe element:
#!xml <frame index="0"> <text edit="true" css="li"> This text is added to content editable areas. </text> </frame>
Refresh
Use refresh
to refresh the browser window (similar to pressing F5).
Example
#!xml <refresh />
Comment
Use comment
to describe the script; the <comment>
element is unrecognized, thus ignored. Avoid using <!-- -->
for comments -- use them instead for blocking out script sections to expedite script testing.
Example
#!xml <comment>This is a comment</comment>
Drag
The drag command starts to relocate an element from its current position to drop location, specified using the drop
command. This emulates drag-and-drop behaviour.
Example
#!xml <drag css="nth-child(1)" />
Drop
The drop command stops relocating an element that was requested to be dragged using a previous drag
command. This emulates drag-and-drop behaviour.
Example
#!xml <drop css="nth-child(3)" />
Cut
The cut
command attempts to copy and delete the highlighted text, putting the text into the copy buffer for a subsequent paste
command.
#!xml <cut />
Updated