Selenium IDE commands


Must know commands for Selenium IDE 47

Over the past couple weeks I’ve written 70 test cases with Selenium IDE.  Since completing the project, I’ve gone back to the first 20 or so and improved them with new commands that I learned and are more reliable in certain situations. In general, when working with elements on a page, the “target” should point to the ID of the element you’re working with and the value is many times optional.  In general, referencing the ID of an element instead of using xPath will save you work in the future when your page structure changes in the future.

Below are the commands I found most useful for testing our web application, which uses many forms and ajax.

echo – I always echo out some text that will help me identify the current test case.  When you’re looking through the logs after running your whole suite of tests, the logs all run together with no break.  You can’t tell which test case had an error unless you echo something like —————- my test case name ————

open – tells the browser to open a specific page.  This is useful if you don’t want the test to navigate to a page and instead just want it to go straight there.  This can be a relative path so you can use it on both a testing and live environment.

Type and TypeKeys – type will place text in an input.  Typekeys will actually mimic entering one key at a time so any onkeyup() functionality you might have going on will work.  We have autocomplete search boxes that required TypeKeys.

verifyTextPresent – Verifies that text appears on the page.  It can be dynamic text that was loaded with ajax.  If it’s on the page in the active window at the time this command is called, it’ll find it.

verifyValue – Verifies the value of an input field.  Provide the id of the input as the target and the value is the text you’re expecting.

click – tell the test to click something on the page.  The target can be referenced with the element ID or xPath as with the other commands.

clickAndWait – Useful for form submissions.  Many times when you’re in record mode and click a submit button, selenium will only record a “click” command.  This will break your test commands following the form submission where you verify the presence of a success message or form values because the next page hasn’t loaded yet.  The “wait” portion will wait to continue the testing when the next page has fully loaded.

select – select an option in a select box by providing the id of the select box and the option value.

pause – Tell the test to pause for a while.  Enter a target of 3000 for 3 seconds.  I started using this command frequently at first, especially when testing ajax.  However, as I went on I found better alternatives since a TCP/IP connection isn’t always reliable and doesn’t get returned on time, every time.

waitForVisible – This command tells the test to wait until an element, often returned by ajax, is visible before continuing.

storeAttribute – Selenium IDE can store variables and allows you to reference them in the same test case or another test case.  The target of this command should point to the text or value to store.  You’ll most likely use xPath for this one.  This example will reference the value of an input field named newTicketId //input[@name=’newTicketId’]@value .  The value of the storeAttribute command will be the variable name to save it as.  Reference the variable in another command with prototype syntax like ${variableName}.