How can I introduce a delay into my custom script?
The custom scripts you configure may run and finish before loading pages, or the transition time between pages may be delayed. Depending on the situation, you can solve this problem by inserting a delay script between the pages you use or adding delays individually to the commands.
For example, authentication may fail due to inadequate page load times or because of the incorrect execution order of the commands.
To resolve the issue, you can try to put the await command between the custom script pages. Click this link for more information on Custom Scripts for Form Authentication.
The await command has the following format:
await invicti.auth.waitTimeoutAsync(2000); |
…where the duration is specified in milliseconds (2 seconds in this example).
Example Customer Script with delay:
For this example, you will create a custom script for one of our testing websites (http://php.testsparker.com/auth/login.php):
To wait for the first page to load up:
await invicti.auth.waitTimeoutAsync(2000); |
To set login information for the second page:
var username = "myusername"; var password = "mypassword"; invicti.auth.setValueByQuery( '#content > div.post > form > input[type="text"]:nth-child(1)', username, 1000); invicti.auth.setValueByQuery( '#content > div.post > form > input[type="password"]:nth-child(3)', password, 1000); |
…where the field value for the username field is set, followed by a delay of 1000ms (1 second); you are treating the password field in the same way.
Now you can introduce a further delay of 2 seconds before submitting the information to the login process:
await invicti.auth.waitTimeoutAsync(2000); |
…and finally we can click on the Submit button, including another delay of 2 seconds after clicking:
invicti.auth.clickByQuery( '#content > div.post > form > input[type="submit"]:nth-child(7)', 2000); |
This example will make the scanner wait for an additional 2000ms before executing the commands for the first page, and then wait another 2000ms before the second one.