What Is Selenium IDE? + 7 Important Selenium IDE Tips
December 13, 2021

What Is Selenium IDE? + 7 Important Selenium IDE Tips

Open Source Automation

Asking yourself what is Selenium IDE? Selenium IDE is an open source test automation tool that can record and playback your actions on the web. By using it, you can automate tests for web applications. Thanks to its convenient features, manual testers who have to repeat their test scenarios are benefiting from the tool. This article shares seven important Selenium IDE tips so that you can use the software more efficiently and ensure the quality of your code. 

Back to top

What is Selenium IDE?

Selenium IDE is an open-source tool for recording browser interactions for Selenium test cases. 

Selenium IDE is easy to install and start: you can just download the tool as a plugin into your web browser, like Chrome and Firefox. Using the tool, you can create simple or complicated test scenarios. 

Like other dev IDEs, you can set breakpoints, pause, and check variables when an error occurs. Plus, you can use your test case again inside another test case, which makes repetitive testing easier and faster. Selenium IDE understands conditional statements such as if and while. This logical handling lets you expand and cover more various test scenarios.

Besides these features, Selenium IDE can also perform:

  • Handling of additional UI components: while interacting with a web page, you may come across additional information windows, notifications, alerts, and others. You can add conditions into your test scripts to handle extra UI components. 
  • Running test scripts simultaneously: you can execute test cases simultaneously to save the overall testing time.
  • Integration into CI: thanks to Selenium’s Command Line Runner, you can integrate Selenium testing into your CI process. With this, you can automatically run tests as developers merge their code.
  • Plugins: you can further extend Selenium IDE features by installing plugins. Also, you can build your own plugins that suit your needs.
  • Granular test cases: you can create granular test cases so that you can use common cases for other tests. Just like function or method in programming, you can design your test script structures so that you don’t have to create the same common test steps again.

📕 Related Resource: Learn more about Selenium vs. Puppeteer: Which Is Better?

Back to top

7 Selenium IDE Tips

We learned that Selenium IDE is such a powerful tool. When you can utilize it properly, you can boost your productivity and ensure quality. Let’s dive into seven important tips for using Selenium IDE.

1. Useful Selenium Commands

There are many commands you can use in Selenium IDE. Although it is not possible to memorize them all, getting familiar with the most essential and frequent commands can help you save time and reduce mistakes. To add the command and target, create your project first and find the inputs as the screen capture below.

Select inputs when creating a project

The commands below are some of the most essential ones that you would use frequently. Getting familiar with them will help you to speed up creating a project. 

Action Commands

Command

Description

Example

open

Navigate to a website

target: blazemeter.com

type

Put a text into a field

target: //input[@name='field_name']

value: blazemeter

click

Click a button

target: //input[@id='green']

value:

pause

Wait for certain seconds

target: 3000

value:

waitForText

Wait for a text

target: //input[@name='field_text']

value: blazemeter

selectWindow

Move to a new window

target: null

value:

Accessors Commands

Command

Description

Example

store

Generate a random number and store

target: javascript{Math.floor(Math.random()*100)}

value: random_num

echo

Write a variable for debugging

target: ${var}

value:

storeText

Retrieve the text of an elements in a table column

target: //table/tbody/tr[5]/td[3]

value: date

Assertions Commands

Command

Description

Example

verifyText

Check if the targeted element has a text that matches a pattern

target: //*[@id="content"]/div[2]/div/h2[1]

value: regexp: blazemeter?

storeXpathCount

Search matched elements and count

target: xpath=//a

value: blaze.*meter

 

These commands are some of the most frequently used commands in Selenium IDE. Knowing commands lets you understand what Selenium is capable of. Keep this list of commands handy and refer to them whenever you want to know if certain actions are possible.

2. String Manipulation

Since you can use Javascript in Selenium, you can also access its string handling functions. Here are five useful functions. While the commands above are Selenium-native and more for selecting values, String manipulation by Javascript gives you an ability to manipulate selected values and provides an immense flexibility in what you can do using the programming language. 

Substring

You can select part of the string using the substring function. For example, let’s say we have a string, “Hi, my name is David” and we want to extract “David”. Then you can use the following substring.

executeScript|varstr=${text};return(str.substring(15));|name
 

This command will run the Javascript code and store the result, “David”, in the name variable. When we use one index in the substring function, it will start at that index and select until the end. If we want to specify the start and end indices, you can use str.substring(15, 20).

Replace

You can replace a matching word with a new word. Let’s say we want to replace the name, “David”, with “Peter”. Then we can use the following command.

executeScript|varstr=${text};return(str.replace("David","Peter");|newname

Split

The split function converts a string into an array split by a defined value. Using the same example, if we want to extract “David”, we can use the function as below.

executeScript|varstr=${text};return(str.split(" ")[4]);|name

 

This will give you “David” as it stores at index 4 in the array.

Concat

When you want to concat two strings, you can do so by the concat function. The sample code below shows how to use it.

executeScript|varstr1=${text1};varstr2=${text2};return(str1.concat(" ",str2));|str_concat

 

Trim

Lastly, the trim function is also useful when you want to remove left and right-padded spaces.

executeScript|varstr=${text};return(str.trim());|name

 

These string handlings are part of the all string functions in Javascript. Although these are not all of them, it will be enough to demonstrate what you can do with string functions.

3. Xpath

Xpath is an important feature that lets you select the value of an HTML element. When you get used to its syntax and build experience, you can access most of the HTML assets giving you a capability to run more detailed tests. In Selenium IDE, you can use Xpath to point to an element. By utilizing Xpath, you can reach almost all elements in an HTML page easily and programmatically as well. Get yourself familiar with Xpath syntax and the capabilities of it then, when you know what you can do, you can build more efficient testing plans.

Xpath=//tagname[@attribute='value']

 

Let’s start with understanding the syntax structure. If we break it down by each elements:

  • // : it means selecting the current node.
  • tagname: the tagname to locate the element
  • @attribute: the attribute name of the node you want to refer to
  • value: the value of the attribute

It will be easier to understand it by looking at some examples. The example below points to a tag that has a link to the Google website.

Xpath=//a[@href='https://www.google.com/']

 

The asterisk below makes this point to any element that has the id value of a surname.

Xpath=//*[@id='surname']

 

You can use ‘and’ or ‘or’ condition in Xpath. The example below selects an element that has an ‘email’ type and has ‘first_email’ as an element’s name.

Xpath=//input[@type='email' and @name='first_email']

 

In Xpath, you can use string match syntax like below. The Xpath below selects all input elements that contain “email” for name. For example, if elements have a name such as “email_01”, “email_02”, and “email_03”, they all contain “email” thus all will be selected.

Xpath=//input[contains(@name, 'email')]

 

Xpath also has various syntax and features. Making yourself familiar with Xpath will certainly give you more testing capabilities.

4. Run Parallel Testing

Parallel testing allows you to run the same tests at the same time in different environments, and you can use this feature to save time and effort. For example, if you want to test the UI for different OS and browsers, running the test sequentially will take your time in proportion to the number of the environments. Using parallel testing, you don’t have to run the same test again and again. Within parallel testing, there are best practices you want to follow.

  • Don’t try to run parallel testing in your local machine since setting up a proper environment is time-consuming. Instead, check Selenium Grid that enables parallel testing across multiple machines.
  • Don’t hardcode values. In programming, hardcoding does not lead to a good result often. The same applies to testing. When you use hard-coded values in a test case, it becomes harder to isolate it and to make it reusable in different scenarios.
  • Plan first to avoid dependencies across test cases: it is hard to modularize dependent test cases and run them in parallel. Like hardcoded values, it may be easier and faster to create dependent test cases. However, in the long-run, dependent cases reduce productivity and efficiency in testing and also block you from running tests in parallel.

5. Utilize CSV to Read Test Data

Instead of using hard-coded data inside your test code, reading data from external datasets in csv can help you prevent dependent tests and manage your test scenarios more efficiently. To read CSV files, you will need to install the Selenium IDE extension by UI.vision. 

The CSV format can be a good choice to have a central dataset and use it across different test cases. You can use the csv read command as below.

csvReadArray|filename.csv|importedCsv

 

Then, the imported csv data can be read by ${importedCsv[row][column]}. The values read from the csv file can be inserted into HTML input elements for testing.

6. Practice Xpath Skills on Test Websites

To hone your skills of Xpath and string handling, it is better to face diverse scenarios. If you keep using similar test cases, your scope of skills can be limited. There are two websites that let you learn Xpath and practice it online.

If you have difficulty in building Xpath even after learning and practicing, you can rely on your Chrome extensions that automatically generate Xpath. One example is XPathMax. This extension creates a Xpath when you click an element.

7. Utilize Plugins that Expand Selenium IDE capabilities

Selenium IDE itself is an extension to your browser. However, by installing other extensions, you can enhance Selenium IDE’s capabilities. You can check each browser’s market place to find a plugin that suits your needs. What’s interesting is you can make other plugins communicate with the IDE via the WebExtension standard. This is an important and unique feature since not all testing plugins allow this. With this feature, you can expand the capabilities of Selenium IDE. For example, you can call the IDE through the Selenium IDE API using browser.runtime.sendMessage. The following code can be executed to call an API.

browser.runtime.sendMessage(SIDE_ID,request)

 

SIDE_ID refers to the IDE’s extension ID that can be found here. In request, you can put a payload like below.

{uri:"/register",verb:"post",payload:{name:"Selenium IDE plugin",version:"1.0.0"}}
 

The uri refers to a resource locator in the IDE and the verb field is a modifier function. You can build more sophisticated interactions as your use cases become advanced. This guide will be a good starting point.

📕 Related Resource: Learn more about How to Run a Selenium Test with TestNG

Back to top

Wrapping Up

This article discussed the concept of Selenium IDE and provided seven essential tips. Although we talked about a single tool, it needed different types of skills such as the commands, string handling, Xpath, and WebExtension. Learning all these without any support may be a burden. Check BlazeMeter. The BlazeMeter blog shares ample knowledge about automatic and continuous testing. The platform also provides a powerful testing solution for users to save time and cost and to maintain their testing environments easily.

START TESTING NOW

 

Related Resources: 
Back to top