I have a python script that uses selenium to automate a web page, focusing focus from the terminal where user input is required.
Is there anyway in python to switch focus to the terminal programmatically?
I will run my program on the Windows command line in Windows 7, if that matters, but the answer to the cross platform will be most useful.
Attempts
Looking at the pywin32 package pywin32 for the win32 API, I have the following:
import win32console import win32gui from selenium import webdriver as wd d = wd.Firefox() win32gui.SetFocus(win32console.GetConsoleWindow()) win32gui.FlashWindow(win32console.GetConsoleWindow(), False) input('Should have focus: ')
SetFocus raises the pywintypes.error: (5, 'SetFocus', 'Access is denied.') due to Microsoft removing the focus feature from another application.
FlashWindow does nothing.
source share