I would suggest you check this link http://docs.seleniumhq.org/exceptions/stale_element_reference.jsp.
In your case, you clicked a button, found the element and then page changed due to the previous click action. Thus you got "Element is not valid".
This might help: wait for page load in selenium