Skip to main content

Example Selenium scripts

The following Selenium scripts demonstrate how to record a script you can use with Veracode Dynamic Analysis.

Use the script examples as templates

To use these scripts as a template:

  1. Copy all JSON from the example.
  2. Paste the JSON into a text file.
  3. Save the text file with the .side extension.
  4. Open the SIDE file in the Selenium IDE or a text editor.
  5. Update the commands and values or add commands.

Example script 1

The following script demonstrates signing in to a web application where the username and password fields are on the same page.

The script commands run in the following order:

  • Opens the URL for the web application.
  • Waits for the sign-in page to load.
  • Enters the username.
  • Enters the password.
  • Selects the sign-in button to sign in.
  • Waits for an element to load, which indicates successful sign in.
{
"id": "b66324ad-1350-4277-85f1-c48b3800a868",
"version": "2.0",
"name": "Login",
"url": "<appURL>",
"tests": [{
"id": "577b18f4-5b2f-49e8-9fc3-e320cd8f00fa",
"name": "Login",
"commands": [{
"id": "03d62bf6-8784-48cc-b319-30e1c809ab11",
"comment": "",
"command": "open",
"target": "</pathToLogin>",
"targets": [],
"value": ""
}, {
"id": "81b9dc4d-7c78-49f9-bc4c-9e2186625169",
"comment": "",
"command": "waitForElementVisible",
"target": "id=<usernameField>",
"targets": [],
"value": "30000"
}, {
"id": "53c5ed70-6548-4e39-b456-d0e5502945d4",
"comment": "",
"command": "type",
"target": "id=<usernameField>",
"targets": [],
"value": "<username>"
}, {
"id": "1b55d2a4-e472-48e6-822d-a5b54a2986d9",
"comment": "",
"command": "type",
"target": "id=<passwordField>",
"targets": [],
"value": "<password>"
}, {
"id": "da24efdf-cdd3-4858-b9f8-52e0666b6d73",
"comment": "",
"command": "click",
"target": "id=<loginButton>",
"targets": [],
"value": ""
}, {
"id": "566c3651-194c-4621-bc87-7f5cb64356fe",
"comment": "",
"command": "waitForElementVisible",
"target": "id=<elementOnSuccessfulLoginPage>",
"targets": [],
"value": "30000"
}]
}],
"suites": [{
"id": "e17f2325-4ac8-46d3-8f25-7b087a41d356",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["577b18f4-5b2f-49e8-9fc3-e320cd8f00fa"]
}],
"urls": ["<appUrl>"],
"plugins": []
}

Example script 2

The following script demonstrates signing in to a web application where the username and password fields are on separate pages.

The script commands run in the following order:

  • Opens the URL for the web application.
  • Waits for the sign-in page to load.
  • Enters the username.
  • Selects the sign-in button to open the password page.
  • Enters the password.
  • Selects the sign-in button to sign in.
  • Waits for an element to load, which indicates successful sign in.
{
"id": "b66324ad-1350-4277-85f1-c48b3800a868",
"version": "2.0",
"name": "Login",
"url": "<appUrl>",
"tests": [{
"id": "577b18f4-5b2f-49e8-9fc3-e320cd8f00fa",
"name": "Login",
"commands": [{
"id": "03d62bf6-8784-48cc-b319-30e1c809ab11",
"comment": "",
"command": "open",
"target": "</pathToLogin>",
"targets": [],
"value": ""
}, {
"id": "81b9dc4d-7c78-49f9-bc4c-9e2186625169",
"comment": "",
"command": "waitForElementVisible",
"target": "id=<usernameField>",
"targets": [],
"value": "30000"
}, {
"id": "53c5ed70-6548-4e39-b456-d0e5502945d4",
"comment": "",
"command": "type",
"target": "id=<usernameField>",
"targets": [],
"value": "<username>"
}, {
"id": "d2ba43a8-e109-415a-a2be-0b19e9ffef75",
"comment": "",
"command": "click",
"target": "id=<loginButton>",
"targets": [],
"value": ""
}, {
"id": "4f9104fd-0f7f-4aeb-885f-b27b1eca4363",
"comment": "",
"command": "waitForElementVisible",
"target": "id=<passwordField>",
"targets": [],
"value": "30000"
}, {
"id": "1b55d2a4-e472-48e6-822d-a5b54a2986d9",
"comment": "",
"command": "type",
"target": "id=<passwordField>",
"targets": [],
"value": "<password>"
}, {
"id": "da24efdf-cdd3-4858-b9f8-52e0666b6d73",
"comment": "",
"command": "click",
"target": "id=<loginButton>",
"targets": [],
"value": ""
}, {
"id": "566c3651-194c-4621-bc87-7f5cb64356fe",
"comment": "",
"command": "waitForElementVisible",
"target": "id=<elementOnSuccessfulLoginPage>",
"targets": [],
"value": "30000"
}]
}],
"suites": [{
"id": "e17f2325-4ac8-46d3-8f25-7b087a41d356",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["577b18f4-5b2f-49e8-9fc3-e320cd8f00fa"]
}],
"urls": ["<appUrl>"],
"plugins": []
}

Example script 3

The following script demonstrates signing in to a web application with multifactor authentication (MFA) enabled using a TOTP scanner variable.

The script commands run in the following order:

  • Opens the URL for the web application.
  • Waits for the sign-in page to load.
  • Enters the username.
  • Enters the password.
  • Selects the button to sign in.
  • Waits for the TOTP field for two-step authentication to load.
  • Enters the TOTP seed from the specified scanner variable.
  • Selects the submit button to sign in with the TOTP seed.
  • Waits for an element to load, which indicates successful sign in.
{
"id": "68c1e8b0-d794-4b37-a7c6-793eb8a434dc",
"version": "2.0",
"name": "Login_TOTP",
"url": "<appURL>",
"tests": [{
"id": "d084a794-2ca2-48ce-bb5c-a4638eeb1f94",
"name": "Login",
"commands": [{
"id": "8b2550d6-ee29-4230-9ccd-f44798a2407a",
"comment": "",
"command": "open",
"target": "<loginPath>",
"targets": [],
"value": ""
}, {
"id": "439e6617-c4d8-49d7-8073-54f638aafc21",
"comment": "",
"command": "waitForElementPresent",
"target": "id=<usernameField>",
"targets": [],
"value": "30000"
}, {
"id": "3c0db2ff-db10-4fcd-8d43-a2c7438e8e1e",
"comment": "",
"command": "type",
"target": "id=<usernameField>",
"targets": [],
"value": "<username>"
}, {
"id": "ee4e1cc9-f9ff-4119-ad3e-b3d3cda39824",
"comment": "",
"command": "type",
"target": "id=<passwordField>",
"targets": [],
"value": "<password>"
}, {
"id": "55f3d219-a84f-471d-a13e-41638ad396dc",
"comment": "",
"command": "click",
"target": "id=<loginButton>",
"targets": [],
"value": ""
}, {
"id": "9840bd4c-52b8-4df8-9b8c-dc7c3bf71b6e",
"comment": "",
"command": "waitForElementPresent",
"target": "id=<totpcodeField>",
"targets": [],
"value": "30000"
}, {
"id": "14b8ff3c-05e8-4dbb-a824-2d6dcf39988d",
"comment": "",
"command": "type",
"target": "id=<totpcodeField>",
"targets": [],
"value": "${TOTP_SECRET}"
}, {
"id": "7c0231b6-84f6-4229-9d0b-928f8df5a378",
"comment": "",
"command": "click",
"target": "id=submit",
"targets": [],
"value": ""
}, {
"id": "5218f117-7594-45f9-b0fe-31ac08144ddf",
"comment": "",
"command": "waitForElementPresent",
"target": "id=<elementOnSuccessfulLoginPage>",
"targets": [],
"value": "30000"
}]
}],
"suites": [{
"id": "34ea279e-bdb6-4c97-b562-1c06635c7898",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["d084a794-2ca2-48ce-bb5c-a4638eeb1f94"]
}],
"urls": ["<appURL>"],
"plugins": []
}