Page tree
Skip to end of metadata
Go to start of metadata

Below, you will find all the Scripting Engine commands that you can use.

Syntax (MUST-READ)

The syntax used by the Scripting Engine is pretty simple. Here are the rules:

  • Each command can be on a separate or on the same line.
  • Each command used should have a set of parenthesis. All command invocations are essentially function calls.
  • Integers are specified as usual.
  • Important: Strings (like selectors, URIs, and texts) are specified by enclosing them in triple double quotes ( """ ). So, a valid string would look like: """this is a string""". Strings can span over multiple lines.

Here are some example scripts, so that you can get familiar with the syntax.

# Example of signing in to your Google account

# If the Chromium switch is OFF
pause(1)
type("""#Email""", """your_email""")
pause(1)
click("""#next""")
pause(1)
type("""#Passwd""", """your_password""")
pause(1)
clickAndWait("""#signIn""")
pause(1)
 
# If the Chromium switch is ON
pause(1)
type("""#identifierId""", """your_email""")
pause(1)
click("""#identifierNext > span > span""")
pause(1)
type("""#password > div.aCsJod.oJeWuf > div > div.Xb9hP > input""", """your_password""")
pause(1)
clickAndWait("""#passwordNext > span""")
pause(1)
# Example of extracting a specific element from a website
extract("""body > div.container > div:nth-child(3) > div.col-md-8""")
# Example of vertical scrolling by 300px down and up, 
# after the webpage becomes visible
blockUntilStart()
repeat(10){
runScript("""window.scrollBy(0,300)""")
pause(5)
}
repeat(10){
runScript("""window.scrollBy(0,-300)""")
pause(5)
}


Available Commands

waitForPageLoad

Waits for the current page to complete loading.

waitForPageLoad()

Pauses execution of the script in the Scripting Engine until the current page has completed loading. This is called in order to delay execution of commands, following navigation or form submission.

openAndWait

Navigates to a URI and waits for the page to complete loading.

openAndWait(webpage)

Navigates to the specified URI and then pauses execution of the script in the Scripting Engine until the page has completed loading. The new web page is loaded within the same Web Viewer, so any session data is preserved.

The webpage parameter is a string containing the URI to navigate to.

type

Type text into form input fields.

type(selector, text)

You can use this command to type information into a specific field on a page. This could be any field, including text fields, text areas, username and password fields.

The selector parameter is a string containing the CSS selector to identify the field to type text into.  The text parameter is the string to type text into the field.

click / clickAndWait

Performs a click operation, and optionally waits for a new page to load.

click(selector) / clickAndWait(selector)

You can use this command to click buttons, links, check-boxes and any other clickable elements on a page.

The selector parameter is a string containing the CSS selector to identify the field to click.

refresh  / refreshAndWait

Trigger a page refresh, and optionally wait for the page to load.

refresh() / refreshAndWait()

You can use this command to refresh a page. This could be useful if a page is updated frequently.

pause

Waits for the specified number of seconds.

pause(seconds)

Pauses execution of the script in the Scripting Engine for the specified number of seconds.

The seconds parameter is an integer with the number of seconds to wait.

repeat

Repeat a set of commands

repeat(times){ ... command_1() command_2() ... }

You can use this command to repeat a set of our Scripting Engine commands in a compact and readable way. 

With the times parameter you can specify the number of times to repeat a set of commands. By setting times parameter to zero, repeat is executed indefinitely.

# Example of using repeat to refresh a webpage every minute, indefinitely
repeat(0){
pause(60)
refresh()
}

runScript / runScriptAndWait

Execute custom JavaScript/jQuery, and optionally wait for page navigation to complete

runScript(your_script) / runScriptAndWait(your_script)

If you are familiar with scripting you can use this command to execute your own custom script.

The your_script parameter is a string containing your JavaScript/jQuery code. 

Note: You can use our 'j' alias for your jQuery code to avoid conflicts or define your own alias. 

# Example of defining your own jQuery alias
var j = jQuery.noConflict();

extract 

Delete all content except for one element and move it to the body

extract(selector)

The selector parameter is a string containing the CSS selector to identify the element. This command also triggers a resize event, so that a responsive element may adapt to the available space.

blockUntilStart

Blocks the execution of the Scripting Engine commands until the web page is visible.

blockUntilStart()

Notice that you can insert this command only once in your Script since the web page will become visible only once and stay visible. For the same reason, blockUntilStart cannot be inserted inside a repeat loop.

Selectors

To identify elements in web pages, we use selectors. Chrome and Firefox browsers allow you to easily find the selector for a specific element.

Finding the selector using Chrome

To find the selector for a specific element or field in a web page using Chrome, do the following:

  1. Right-click on the element you want to act upon and select Inspect
  2. Right-click in the highlighted area in the DevTools panel and select Copy → Copy selector


Finding the selector using Firefox

To find the selector for a specific element or field in a web page using Firefox, do the following:

  1. Right-click on the element you want to act upon and select Inspect Element(Q).
  2. Right-click in the highlighted area in the DevTools panel and select Copy → CSS Selector

Note: Firefox CSS selectors are usually shorter and more accurate.


  • No labels