Browser and variable access by JavaScript | Selenium Automation Testing

Browser and variable access by JavaScript | Selenium Automation Testing

Browser and variable access by JavaScript – Storing variables in Selenium IDE

  • Selenium functions store, storeValue, and storeText store some data for later access.
  • Selenium uses a map called storedVars to store the data.

You can store strings.

Example:

store
this text is a string
variable1

You can use previously stored variables. ${varaiable_name} gives us access to the storedVars map.

Example:

store
${variable1} okay?
variable2

* varaible2 will now be ‘this text is a string okay?’
You can use pure javascript expressions. With javascript{} we can use pure javascript:

store
javascript{Math.random()}
random_variable

So you can access the storedVars map directly in a javascript expression:

store
javascript{storedVars[‘random_variable’]}
random_variable_copy

Storing variables in Selenium IDE
* random_variable and random_variable_copy should be exactly the same.
Note that if you use:

store 0 zero

zero will be 0, but casted as a string. So later if you use for example:

javascript{storedVars[‘zero’]+1}

You will get ’01′ instead of ’1′.
So when you need 0 as an integer you should store your variables using javascript:

getEval storedVars[‘zero’] = 0;

* getEval gets the result of evaluating the specified JavaScript snippet.

How can I access global javascript variables in the browser console?

Build a Visualforce page with showHeader="false"
<apex:page showHeader="false">

Create a javascript global variable inside the page:

<script> var myVar = 'Hello'; </script>

Save your test page and open it via its URL.

http//[instance].salesforce.com/apex/[pagename]

Now in the browser console (F12 sometimes), type

window.myVar

and return gives you

'Hello'

Now insert this visualforce page as a section in a standard page layout.

Load the standard page and type in the console:

window.myVar

Which returns

undefined

What ?

Where art thou ?

 

Selenese – Selenium Commands
Selenium Testing | Event Firing

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?