Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Selenium Essentials
  • Table Of Contents Toc
  • Feedback & Rating feedback
Selenium Essentials

Selenium Essentials

By : Sams
5 (1)
close
close
Selenium Essentials

Selenium Essentials

5 (1)
By: Sams

Overview of this book

If you are a developer who wants to migrate from Selenium RC or any other automation tool to Selenium WebDriver, then this book is for you. Knowledge of automation tools is necessary to follow the examples in this book.
Table of Contents (7 chapters)
close
close

Selenium IDE JavaScript functions

In addition to user-defined JavaScript commands introduced through user-extensions.js, the Selenium IDE allows the user to create JavaScript queries or functions directly in the Target field. For example, let's run a Google search by getting a random number between 1 and 100, as follows:

Selenium IDE JavaScript functions

The following HTML source tags let you convert the steps into runnable test scripts:

<tr>
  <td>store</td>
  <td>javascript{'Random number ' + Math.floor(Math.random() * 100);} </td>
  <td>search</td>
</tr>
<tr>
  <td>echo</td>
  <td>${search}</td>
  <td></td>
</tr>
<tr>
  <td>open</td>
  <td>/</td>
  <td></td>
</tr>
<tr>
  <td>type</td>
  <td>id=gbqfq</td>
  <td>${search}</td>
</tr>

Simple JavaScript execution

The predefined Selenium IDE JavaScript command runScript is a very powerful command that lets the user execute simple JavaScript functions directly from the IDE, for example, javascript{alert("Hello!")}.

Let's see how we can disable an active textbox and enable an inactive textbox using the following code snippet:

document.getElementsByName('****')[0].setAttribute('disabled', '')
document.getElementsByName('****')[0].removeAttribute('disabled');
Simple JavaScript execution

Mouse scroll

The scroll event is currently unavailable in the Selenium IDE. However, the user-extensions.js file includes a JavaScript method that lets you scroll the mouse through the web page.

Refer to the Google site https://sites.google.com/site/seleniumworks/selenium-ide-tricks to download user-extensions.js. This user extension file includes IDE commands like while, endWhile, gotoIf, gotoLabel, and push. Increase the value to 10 based upon the vertical length of the web page, as shown in the following screenshot:

Mouse scroll

Parameterization using arrays

The Selenium IDE command storeEval is used to store values in a variable while running scripts, whereas storedVars is a JavaScript associate array with string indexes containing variables. In the following example, storeEval reserves the list of rivers in an array, and getEval is a command for initiating and incrementing the values. Some of the commands used in this section are purely user-defined, such as while, endWhile, and so on. Here, the endWhile command is used to break the loop once the value inside the array reaches the maximum limit. The following screenshot gives us a clear idea of what is being discussed here:

Parameterization using arrays

Let's see another example of advanced parameterization concepts using the Selenium IDE. Refer to the Google site https://sites.google.com/site/seleniumworks/selenium-ide-tricks to download the user-extensions.js file. The following screenshot captures the essence of this discussion:

Parameterization using arrays

In this example, the values are pushed into the array manually, and it does a Google search one by one.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Selenium Essentials
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon