Monday, August 1, 2016

Javascript in Selenium IDE

I have had a couple of questions about various javascript that would be useful in testing with Selenium IDE, others have just had question on how to execute the various javascript commands in IDE. So, here are a few that I have questions about the most, hopefully this helps.
First, is the alert button for a inner html of a specific element such as a paragraph or a link.
The first thing you have to do is store the inner html in a variable. For this you actually don’t need javascript but there is a command built in call storeText, imagine that. The target for this is the html element that has the text you wish to store, common is an input box. Next the value is the variable name to which you wish to save it.
Next is the Javascript, now off the bat you would think to use the runScript command with alert{${variableName}} in the target but the problem with this is that it just runs the javascript since the variable is not stored in javascript you have to use the command getEval which will run both the javascript code and evaluate the variable.
The only other piece of javascript I am going to talk about here is dealing with API’s. If you don’t know what these are you don’t need to worry about this. If you do know what this is and want to use these commands, a lot of this depends on the API functions that are built in your website.
So quick example is dealing with the canvas html object and this website has an API that allows you to find blocks on the canvas element.

If you have any questions or comments please leave them below.


  1. Thank you. I have looked at the list of headless browsers for automation and have come to the conclusion the best beginning approach is to go with something that has lots of documentation, hence, I arrive at Selenium, hoping to learn javascript automation coding.

  2. Just found your post by searching on the Google, I am Impressed and Learned Lot of new thing from your post.