The problem is that xprop is blocking for the mouse click so it needs to be done in the background. The wait
is not strictly necessary, but makes the script exit more cleanly by waiting for xprop
to complete.
#!/bin/bash
xprop | grep WM_NAME\(STRING\) &
pid=!$
sleep 1
xdotool mousemove 10 40 click 1
wait $pid