A variable is a value (eg a string or a number) referred to by a name. In GoScript we use variables to hold values extracted by JavaScript.
Some variables are also passed in from outside the script, such as the username and password in the case of Authentication GoScripts
To create a new variable, or assign a new value to an existing one, use the syntax
name := js: [some javascript that produces a value]
For example:
myNewVariable := js: document.documentElement.textContent.match(/myRegularExpressionPrefix: ([0-9]{3})/)[1];
This creates a variable with the name myNewVariable and the value extracted from the page body using a regular expression. If myNewVariable was already associated with a value, the old value is replaced with the new one.
Now in your script you can refer to the variable name, wrapped in {}, instead of the value. For example:
type: {myNewVariable}
This uses the type command listed in Commands (above) to type the value of myNewVariable, ie it will type 123.
Comments
0 comments
Article is closed for comments.