Soap dispenser doesn't open

My Whirlpool dishwasher is just about 5 years old. Soap cup doesn’t open. It used to happen every once in a while, recently happened more frequently, and now it’s happened twice in a row.

How do I determine which part needs replaced?

Here are your parts
http://www.appliancepartspros.com/partsearch/modelsearch.aspx?model=DU840SWPT0

You will have to open it up and check what is going on with it/.
This should help
https://secured.whirlpool.com/Service/SrvTechAdm.nsf/2cd44500d572193285256a45004fd9d6/56e33eb0e839a7fa85256a8e00510938/$FILE/4322430.pdf

If using liquid detergent make sure the dispenser is clean and not sticking closed due to detergent residue