Wiki

Clone wiki

Scripted Selenium / Reserved Commands

Overview

This section describes plans for future commands.

Highlight

The highlight command highlights starting from a position that matches a regular expression until the end of the text element.

#!xml
<highlight id="element_id" from="starting text" />

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 />

Paste

The paste command will paste the copied text into a given element. The prefix attribute can be used to inject text in advance of the pasted content. Padding several spaces in the prefix is required when pasting into a contenteditable iframe.

#!xml
<paste id="element_id" prefix="          " />

Include

The include command will include another script. For example:

#!xml
<include file="/path/to/script.xml" />

Variable

The variable command will define a global value that can be used throughout the script. For example:

#!xml
<script>
  <variable name="name.first" value="Alan" />
  <variable name="name.last" value="Turing" />

  <text css="input[name='first']">${name.first}</text>
  <text css="input[name='last']">${name.last}</text>
  <click id="input[type='submit']" />

  <click link="${name.first} ${name.last}" />
</script>

Macro

The macro command will define a named script sequence. For example:

#!xml
<macro name="search">
  <variable name="site" default="duckduckgo" />
  <variable name="text" />
  <variable name="go" />
  <script>
    <visit>http://${site}.com</visit>
    <text css="${text}">site:reddit.com unit testing</text>
    <click css="${go}" delay="2500" />

    <comment>Reset the delay to normal.</comment>
    <pause delay="250" />
  </script>
</macro>

Then the macro can be re-used:

#!xml
<search site="google" text="#lst-ib" go=".jsb > center:nth-child(1) > input:nth-child(1)" />
<search site="duckduckgo" text="#search_form_input_homepage" go="#search_button_homepage" />

Comment

The comment command will write the contents to standard error, standard output, or a file. Examples:

#!xml
<comment log="standard-output">Log to standard output</comment>
<comment log="standard-error">Log to standard error</comment>
<comment log="/var/log/scripted-selenium/logfile.txt">Log to a file</comment>

Scroll

The scroll command will scroll the browser viewport to a specific element, smoothly. For example:

#!xml
<scroll id="element-id" time="1000" />

The time attribute controls how long the scrolling should take from start to finish.

Key

Sends a keystroke to a web page element.

#!xml
<key code="ENTER" />
<key code="DIVIDE" modifiers="CTRL+ALT+SHIFT" />

Updated