I assume you already know how to record and run actions and the main problem is selecting the gradient background?
If it is always the same exact gradient and size, you can use the difference blend mode to help create the selection. Overlay the gradient and the darkest blacks will be your selection. Or at least a rough selection that you need to smooth out some.
If the sizes and the gradients vary, it won’t be a simple matter. It is possible to create a rather complicated action that will select two colors from the image and create a gradient with them and then do the difference blend to get the background areas selection.
In any case, you probably want to do it so that you can adjust the results manually, i.e. use layers that you can modify if the action doesn’t dial it in perfectly. I suggest using layers masks, as you will likely need to paint in some details in the dresses that get mistaken for the background.