A couple of things you can try -
- After Dialog() statement , can you put some wait(5). [We can optimize timing later.]
- As soon as SAPGUISession() window is opened, try getting the hwnd of it. Using Activate method activate the window to get it in foreground and then follow through rest of the steps.