We are not quite sure what is your setup. The only way to clear the selection using our predefined UI we could think of is to enter HeaderFooterEditMode. However, I tested the code you pasted and it looks like when closing the mode the selection, as you observe, is set again and the command (ExitHeaderFooterEditModeCommand) is executed as expected.
That said, can you please elaborate on your overall scenario or even better open a support ticket and send us a sample project we can use for testing.
Thank you for your cooperation!
All the best,