Sanju,
If you post the Selenium code that does not work there is insufficient
information to help you. If this code doesn't work it is obviously
wrong.
I can say a few things. First, try adding an "xpath=" to the string. I
have found this seems to make the code work a little faster and
therefore better.
Second, that is a really long xpath, you might want to see if you can
shorten it. Have a look at
http://darrellgrainger.blogspot.com/2010/03/how-to-pick-identifiers.html
for tips on how to shorten it.
Third, usually if you have a collapse/expand widget, it uses
javascript to alter the DOM. The item which you click to expand is
often different from the item to collapse. So you want to examine the
DOM when it is expanded to find the 'collapse' identifier and
collapsed to find the 'expand' identifier.
Posting the HTML code would probably be the most helpful for me to
provide you with an answer to your problem.
Darrell