DéjàClick can run user-defined JavaScript code on web pages when replaying recorded transactions. This way you can interact with web page contents using not only the recorded actions. For example, you can:
XMLHttpRequest
object
You can run JavaScript code after specific events in your DéjàClick script. To specify the code to run, use the JavaScript Validation properties of an event.
Note: |
This feature requires the knowledge of JavaScript and DOM. You can use the following resources as reference materials: |
In DéjàClick scripts used to monitor transactions, you usually use JavaScript validations to verify values on web pages. However, you are not limited to validations only. You have the full power of JavaScript to do almost anything you can think of:
document.cookie
)
You can create JavaScript validations when recording, editing, and replaying scripts.
To create a validation during recording:
Click Add validations () and select Add JavaScript validations.
Click anywhere within the web page or frame you want to validate using JavaScript.
Configure the validation.
To create a validation when editing the script:
Open the DéjàClick sidebar.
Record a script or open a previously recorded script.
In the script, select an action (web page) or event for which you want to add a validation rule.
The validations you have added to an event will run after the event finishes. The action validations will run after the last event in the action.
Switch to the Properties tab in the lower half of the DéjàClick sidebar.
Expand the JavaScript Validation group.
If you do not see the JavaScript Validation group, click and select Advanced in the Display level drop-down list.
Click Add.
Configure the validation.
To create a validation when replaying the script:
Pause the replay at the page you want to validate.
Tip: | To set a pause before replaying, right-click the needed action (web page) or event and select Pause. |
Click Add Validations () and select Add JavaScript Validations.
Click anywhere within the web page or frame you want to validate using JavaScript.
Configure the validation.
To configure a JavaScript validation:
Enter the JavaScript code to run. The last statement in the code must evaluate to true
or false
. See Write JavaScript Code for Validations below.
Select which result to consider as a failure – true
or false
.
Select what to do if the validation fails:
(Optional) Under Evaluation Options, select the document (web page or frame) to validate. By default, this is a web page that contains the current event’s target object. If your web page contains several frames, or if it opened other web pages (for example, popups), you may need to select Evaluation Options for a specific document, replay the script, and try again.
Once ready, click OK to save the settings.
You can save the modified script to your computer, or upload it to AlertSite – a worldwide network of monitoring stations – for remote execution.
You can use any JavaScript code whose result is true
or false
. For example, it can be a single expression:
JavaScript
It can also be a multi-line script:
JavaScript
The final result is the value of the last expression. The trailing semicolon (;
) is optional.
If the code is a function call that does not return a value, append ; true
at the end of the line to use true
as the result:
JavaScript
The result of the code can also be a string or a number. DéjàClick will convert it to the corresponding boolean value:
0
, ""
(empty string) – false
1
, -1
, "done"
, "true"
– true
"0"
, "false"
(in quotes) –true
If the final result have some other type (an object, array, and so on), it is ignored for security reasons. In this case, DéjàClick ignores the validation and continues the replay.
Use window.document
instead of document
if you are also going to replay your DéjàClick script in Firefox.
Use Chrome Developers Tools (F12) to learn the IDs of web page elements.
Run your DOM-related code in the browser’s JavaScript console (Ctrl+Shift+J) first to make sure it runs successfully.
DéjàClick uses the chrome.tabs.executeScript method to run JavaScript validation code on web pages. The code runs in an isolated environment. This means that it can access web pages’ DOM, but it cannot access other JavaScript functions and variables on the page. Similarly, the scripts cannot access the local file system. The other restrictions depend on specific Chrome and website settings.
This code verifies that the warning
element’s foreground color is red.
JavaScript
The code below verifies that the web page was last modified less than 12 hours ago. Add this code to the first event of a web page (action).
JavaScript