Storing information from the page in the test
Sometimes, there is a need to store elements that are on the page to be used later in a test. It could be that your test needs to pick a date that is on the page and use it later so that you do not need to hardcode values into your test.
Once the element has been stored, you will be able to use it again by requesting it from a JavaScript dictionary that Selenium keeps track of. To use the variable, it will take one of the following two formats: it can look like ${variableName}
or storedVars['variableName']
. I prefer the storedVars
format as it follows the same format as within Selenium internals. To see how this works, let's work through the following example:
- Open up Selenium IDE and switch off the record button.
- Navigate to http://book.theautomatedtester.co.uk/chapter1.
- Right-click on the text Assert that this text is on the page and go to the
storeText
command in the context menu and click on it. - A dialog will appear as shown in the following screenshot. Enter the name of a variable that you want to use. I have used
textOnThePage
as the name of my variable. - Click on the row below the
storeText
command in Selenium IDE. - Type
type
into the Command textbox. - Type
storeinput
into the Target box. - Type
${textOnThePage}
into the Value box. - Run the test. It should look like the following screenshot:
Once your test has completed running, you will see that it has placed Assert that this text is on the page into the textbox.