The best and fastest way to find an element by id. In many browsers, the time the element spent on it id is linear or even constant. very fast.
For example, for an element defined as:
<input type="text" name="passwd" id="passwd-id" />
You should find it as follows:
selenium.type("passwd-id", "test");
Or if you are using the webdriver API:
element = driver.findElement(By.id("passwd-id"));
If the elements on your pages do not have identifiers, add them! or ask developers to add them!
The next best way to search for items is by name. This is pretty fast, especially if the name is unique on the page.
For instance:
selenium.type("passwd", "test");
Or if you are using the webdriver API:
element = driver.findElement(By.name("passwd"));
A third way to find an element is to use a CSS selector. Modern browsers are very good at finding elements this way.
The worst way to find an element is to use xpath. xpath is slow, fragile, and hard to read.
Simon Stewart, a major contributor to Selenium, answers this question here: http://www.youtube.com/watch?v=oX-0Mt5zju0&feature=related look for a timestamp 39:00
There is also good information here: http://seleniumhq.org/docs/02_selenium_ide.html#locating-elements