HOWTO: CHECK WHETHER AN ELEMENT EXISTS OR NOT

Use verifyElementPresent, as below?

HOWTO: COUNT THE NUMBER OF ELEMENTS OF A PARTICULAR TYPE

HOWTO: CHECK WHETHER AN ELEMENT DOES/DOESN'T HAVE A PARTICULAR CLASS?

Check whether an element containing the required class exists via XPath and verifyElementPresent:

verifyElementPresent xpath=//*[@id='yui-dt0-bdrow0-cell4'][contains(@class, 'changed')]

or

verifyElementNotPresent xpath=//*[@id='yui-dt0-bdrow0-cell4'][contains(@class, 'changed')]

HOWTO: SELECT BY ATTRIBUTE VALUE

Don't attempt to use any of the *Text functions (even with XPath)--they don't work. Instead, you need to use the special *Attribute functions e.g.:

waitForAttribute xpath=//*[@id="fooimg"]/@alt something

(Could also use a variable of the verifyElementPresent + XPath trick, above.)

HOWTO: GET THE STATUS CODE OF A RESPONSE

HOWTO: EXECUTE JAVASCRIPT

I haven't been able to get this working completely correctly, but you should be able to use getEval, with the caveat that the scope is weird:

this.browserbot.getCurrentWindow().document.foofn(9)

(You may need to explicitly assign document.foofn = foofn.)

TIP: AJAX TESTING STRATEGIES

You'll probably want to use one of the waitFor* functions.

Strategy 1:

Arrange for a variable to be set/unset when Ajax requests are active. (Prototype maintains an Ajax.activeRequestCount variable that may be useful; you may need to do document.ajax = Ajax so that it's accessible from the scope of the selenium test.)

Then, in your selenium test, wait for ajax to be equal to 0:

waitForCondition selenium.browserbot.getCurrentWindow().document.ajax.activeRequestCount == 0 10000

(The problem with this is that if your test depends upon the display being refreshed, the refresh might not have happened by the time selenium does the test, since selenium is triggered on the Ajax completion, rather than the refresh.)

Strategy 2:

Wait for an element to appear, or become visible (e.g. error message):

waitForVisible map-container

Strategy 3:

Store how many elements of a particular type there are and wait for the number to change:

storeEval selenium.browserbot.getCurrentWindow().document.getElementById("search_results").childNodes.length count

clickAt xpath=//*[@id="basket_contents"]/dt 5,5

waitForNotEval selenium.browserbot.getCurrentWindow().document.getElementById("search_results").childNodes.length ${count}

If the condition is boolean, or more easily expressed as a boolean, you can create a Javascript boolean value as follows:

waitForEval selenium.browserbot.getCurrentWindow().document.getElementById("search_results").childNodes.length > 10 javascript{true}

FAQ: WHAT'S THE DIFFERENCE BETWEEN assert* AND verify*?

If an assert fails, the test suite is stopped immediately. If a verify fails, then that particular test fails, but the remainder of the suite is processed as usual. You might want to use an assert test to check if you're on the right page, for example, and verify tests to check the page for particular elements.

FAQ: I CAN'T MATCH ELEMENTS BY POSITION (XPATH)!

If you're having trouble with e.g.

xpath=//input[@alt='SAVE'][2]

try this instead:

xpath=/html/descendant-or-self::input[@alt='SAVE'][2]

(Don't know why this makes a difference, but it does.)

TIP: SELENIUM DOCUMENTATION

http://release.openqa.org/selenium-core/0.8.0/reference.html

Element locators:

http://release.openqa.org/selenium-core/0.8.0/reference.html#locators

String match patterns:

http://release.openqa.org/selenium-core/0.8.0/reference.html#patterns

TIP: VARIABLE INTERPOLATION

${name} can be used to interpolate almost everywhere:

store Michael foo

type name ${foo}

TIP: JAVASCRIPT EVALUATION

Similarly, javascript{code} can be used to execute Javascript almost everywhere:

store javascript{'merchant' + (new Date()).getTime()} merchantId

type textElement javascript{storedVars['merchantId'].toUpperCase()}

HOWTO: USE user-extensions.js

It's in core/scripts; here's a sample:

Selenium.prototype.doAlert = function(s) { alert(s); };

Then you can do:

alert Hullo, World!

or:

alert ${count}

FAQ: HOW TO STOP THE SELENIUM IDE ONCE STARTED?

???