Skip to content

Commit b19214b

Browse files
[Add] optional pid matching for precision
1 parent b3e183b commit b19214b

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Framework/Built_In_Automation/Desktop/Windows/BuiltInFunctions.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,9 @@ def _get_main_window(WindowName):
12451245
for i in MainWindowsList:
12461246
if i.Current.ProcessId in current_pid_list:
12471247
NewMainWindowsList.append(i)
1248-
1249-
for MainWindowElement in NewMainWindowsList:
1248+
1249+
found_windows = []
1250+
for MainWindowElement in MainWindowsList:
12501251
try:
12511252
if WindowName[2] == "pid":
12521253
try:
@@ -1257,12 +1258,19 @@ def _get_main_window(WindowName):
12571258
else:
12581259
NameS = MainWindowElement.Current.Name
12591260
if _found(WindowName, NameS):
1260-
CommonUtil.ExecLog(sModuleInfo, "Switching to window: %s" % NameS, 1)
1261-
autoit.win_activate(NameS)
1262-
return MainWindowElement
1261+
if MainWindowElement.Current.ProcessId in current_pid_list:
1262+
CommonUtil.ExecLog(sModuleInfo, "Switching to window: %s" % NameS, 1)
1263+
CommonUtil.ExecLog(sModuleInfo, f"pid matched: {MainWindowElement.Current.ProcessId}", 5)
1264+
autoit.win_activate(NameS)
1265+
return MainWindowElement
1266+
else:
1267+
found_windows.append(MainWindowElement)
12631268
except:
12641269
pass
1265-
1270+
if len(found_windows) > 0:
1271+
CommonUtil.ExecLog(sModuleInfo, "Switching to window: %s" % found_windows[0].Current.Name, 1)
1272+
autoit.win_activate(found_windows[0].Current.Name)
1273+
return found_windows[0]
12661274
return None
12671275
except Exception:
12681276
CommonUtil.Exception_Handler(sys.exc_info())

0 commit comments

Comments
 (0)