Take the 2-minute tour ×

I have to find out XPath for code :

<input type="button" onclick="redirectToUserList(5);" class="btnManage" value="Manage Users" style="background-color: transparent;">

Using firebug the XPath is :


But how can I have a shorter xpath like I wish following could run: //input[@value='Manage Users']

Please advice how to find shorter XPath using standard syntax?

share|improve this question
Please, show the data so we can help you. –  choroba Oct 7 '12 at 14:01
Using the XPath pseudo-operator // can be very inefficient (causes a complete traversal of the whole document tree), compared to using a specific path. Therefore, while possible, this isn't generally recommended. –  Dimitre Novatchev Oct 7 '12 at 14:39
"how can I have a shorter xpath like I wish following could run: //input[@value='Manage Users']" What makes you think that this XPath expression can't run? Did you try it and get an error? If so, what did the error message say? Did you get wrong results? If so, what were the results and how did they differ from what you expected? –  LarsH Oct 8 '12 at 5:54

3 Answers 3

You do not need to search for id or name, you can search for any attribute.

For example:

  //input[@value="Manage Users"]

which sounds unique

share|improve this answer

It is not mandatory to use id or name. You can use any attribute of that element.

Following are different xpaths for given locators

 1. "//input[@value='Manage Users']"
 2. "//input[contains(@onclick,'redirectToUserList')]"
 3. "//input[@type='button' and @class='btnManage']"
share|improve this answer

As an addon to above given answers any specific attribute like id or name is never necessary.

We mostly take id and value to identify an element uniquely because other attributes may specify some other locators as well.

If any attribute is not creating confusion with some other locator you can choose it without any worry.

Lastly if you are not so good in writing xpath and also dont like large xpaths given by firebug just install an addon of firebug called as Firepath it will give you the shortest feasible xpath.

You can also go with other addons like Xpath Checker etc.

share|improve this answer

Your Answer


