'Select tab with exact title on browser with pygetwindow

I'm trying to select a specific tab on my browser with a title, I can do that if the tab is selected on browser, I'd like to select it if it's not selected on my browser and maximize it, I'm using this code to that:

import pygetwindow
import time

window = pygetwindow.getWindowsWithTitle('Name of my tab')[0]
time.sleep(2)
window.maximize()

I'm also trying to use the same code to maximize my cmd after doing the job, but in this case, not working.

import pygetwindow
import time

window = pygetwindow.getWindowsWithTitle('Name of my tab')[0]
time.sleep(2)
window.maximize()
time.sleep(2)
window = pygetwindow.getWindowsWithTitle('C:\Windows\System32\cmd.exe - python main.py')[0]
time.sleep(2)

Any idea how to handle with that?



Solution 1:[1]

i am also trying to get the chrome window in focus using the first script. It works if the chrome window has no other tabs open but fails if other tabs are open. How are you managing that. I generally have 4 tabs open in the same chrome window.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Swapnil Kothari