YumYumYum YumYumYum - 2 months ago 20
Python Question

Python - why its not able to find the window title?

I have following code and its unable to activate the window title "Stack Overflow" and sending the f11 to wrong GUI.

Is this a Python bug? Why its not working?

import subprocess
from subprocess import Popen
import win32com.client as comctl
import time

def chromes():
url='https://stackoverflow.com'
cmd='C:/Users/tpt/AppData/Local/Chromium/Application/chrome.exe'
Popen([cmd, url, '--window-position=0,0', '--user-data-dir=C:\\iplay'])

chromes()
time.sleep(5)

wsh =comctl.Dispatch("WScript.Shell")
aa = wsh.AppActivate("Stack Overflow")
wsh.SendKeys("{F11}")

Answer

Like this :

import win32gui
import win32api
import win32con

def enumHandler(hwnd, lParam):
    if win32gui.IsWindowVisible(hwnd):
        if 'Stack Overflow' in win32gui.GetWindowText(hwnd):
            win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_F11, 0)


win32gui.EnumWindows(enumHandler, None)

But no idea about which tab effected ?