In certain complex situations you may need to use conditionals in your GoScript, so that part of the script is only executed if a certain condition is met. A (somewhat) common example of this is a login process where you are presented with a different login screen depending on the presence or lack of certain cookies, so your GoScript needs to follow one process on the first visit and a different process on subsequent visits within the same browser session.
The code following the condition should be indented. Once the indentation stops the condition has ended and further commands will be run regardless of the condition.
Instruction |
Description |
Examples |
if see |
If the text following "if see" is found on the page within the timeout period (usually 30 seconds) then the following indented code is executed. |
if see Some text that might appear on the page If the string "Some text that might appear on the page" is seen within the timeout period the script proceeds to load https://puppies.com, otherwise it continues to the next line |
There is no punctuation in this command: do not use a colon as you would in a wait for: command, and do not place quote marks around the string you are checking for. |
||
elif see |
The same as an "if see" command, but only runs if the proceeding "if see" condition was false (ie the specified string was not seen). |
if see Some text that might appear on the page If the string "Some text that might appear on the page" is seen within the timeout period the script loads https://puppies.com. If that was not seen, but "Some different text" is seen, the script loads https://kittens.com. |
The script will wait for the timeout for each if see and elif see until one is found, so can end up with quite a long pause if you have several conditions and none, or a later one, is seen. |
||
else |
If the proceeding if see statement (and any elif see statements, if present) was false then the following indented code is executed. |
if see Some text that might appear on the page If the string "Some text that might appear on the page" is seen (within the timeout period) the script loads https://puppies.com, and waits for "Puppies for sale" to appear. If that was not seen, but "Some different text" is seen, the script loads https://kittens.com and waits for "Humans wanted" to appear. If neither was seen the script loads https://www.seeturtles.org/ and clicks the Cool Turtles button. |
Comments
0 comments
Article is closed for comments.