Been doing some record play back with selenium and wanted to capture a few handy commands for storing variables, and making elements lose focus.

Storing a variable

This will store a random number in the variable invoicenumber.

You can then access the variable to type into a textbox by doing this

Or use it later in a selector to double click something by doing this

Lose focus with the blur command

Sometimes in selenium popups and dialogs don’t close the way they should when you are clicking through the application with a mouse.

If this has happened to you, try entering a key press on another field with the value ‘\9’ and then firing the ‘blur’ event.

This helped me close a pesky calendar pop-up that wouldn’t go away and prevented me from submitting a form.

Check if a button is disabled

Update: To select text within a span use the following xpath (requires jQuery):

//span[text()=’${invoicenumber}’]
td > span:contains(“71378”)

Advertisement