How to Use Selenium IDE – Quick Tips

In our previous posts on Selenium IDE, you must have seen its download instructions and read about some additional add-ons you can use on top of it. Now, it’s time to give you some cracking tips so that you can use Selenium IDE for the maximum benefit.

Some of these can be surprisingly handy for the testers to perform quick testing. For best results from this post, please try to use Selenium IDE while reading this post. It’ll be a good learning experience.

How to Use Selenium IDE – Quick Tips.

The most obvious way to use Selenium IDE is through its record and play feature. But there are certain actions, accessors, and assertions which you can use to edit the recorded test cases. So that you can speed up automation and increase test coverage.

1- Selenium IDE Action Commands.

You can perform many browser actions using the Selenese commands. Examples are clicking a hyperlink or filling out a form. Can be done by running the IDE in “record mode”.

PurposeCommandExample
1- Navigate to a website. opentarget: google.com
value:
2- Type into a text field.typetarget: //input[@name=’name’]
value: techbeamers
3- Click on a radio button.clicktarget: xpath=(//input[@name=’category’])[4]
value:
4- Select a language.clicktarget: //select[@name=’Java’]
value: label=Langugage
5- Locate an input element using a partial string.typetarget: //input[contains(@ref, ‘author_’)]
value: 15
6- Add a wait command.pausetarget: 5000
value:
7- Check for a text to appear on a page.waitforTexttarget: css=label
value: Selenium
8- Switch to a new window.selectWindowtarget: null
value:

 

2- Selenium IDE Accessors Commands.

You can use accessors commands to fetch and save the state of web elements.

PurposeCommandExample
1- Generate a random number and store.storetarget: javascript{Math.floor((Math.random()*10)+1)}
value: random_num
2- Pick a random option from a drop-down.storeXpathCounttarget: //select[@name=’category’]/option
value: default
storetarget: javascript{Math.floor(storedVars[‘counter’]*Math.random())}
value: rand
selecttarget: //select[@name=’category’]
value: index=${rand}
3- Choose a random radio button.storeXpathCounttarget: //select[@name=’recent posts’]/option
value: default
storetarget: javascript{Math.floor(storedVars[‘counter’]*Math.random()) +1}
value: rand
clicktarget: xpath=(//input[name=’recent posts’])[${rand}]
value:
4- Log a variable for debugging.echotarget: ${var}
value:
5- Capture inner text of a web element of a table column.storeTexttarget: //table/tbody/tr[3]/td[3]
value: date

 

3- Selenium IDE Assertions Commands.

like Webdriver, you can place assert commands in Selenium IDE test cases to check the state of web elements.

PurposeCommandExample
1- Assert for a text present on the web page.verifyTexttarget: xpath=(//html/body/div[2]/h2/span)
value: Selenium
2- Use regEx in the above example.verifyTexttarget: xpath=(//html/body/div[2]/h2/span)
value: regexp:[Se]enium
3- Search using a glob.storeXpathCounttarget: xpath=(//html/body/div[4]/h2/span)
value: glob:*nium

 

4- Selenium IDE Test Case/Test Suite.

In Selenium IDE, it’s easy to create test cases and convert then into test suites. Add them to version control system for use in nightly automation.

4.1- Start writing a test case.
4.2- Save the test case.
4.3- Prepare to save it as a test suite.
4.4- Add it to version control.

Above sequence of operations works best for Selenium IDE.

 

Final Thought.

Hopefully, you can now use Selenium IDE better than you were doing earlier. Though it’s always best to run the IDE test cases at top-speed but they may fail for the slow websites. So, you need to control the speed in such cases.

 

Best,

TechBeamers.

 

One Response

  1. Sean E Reply