如何使用 PyWinAuto 将应用程序添加到列表中?
How to add an application to a list with PyWinAuto?
我正在尝试在 Python 上自动化处理浏览器 window 的应用程序。
我需要在打开后将应用程序添加到列表中,这样我就可以随时轻松地返回到他们的window。
从下面的代码我可以得到应用程序:pywinauto.application.Application object at 0x0000020C78574FA0
但是如果我尝试从命令 applications.extend(app)
添加到列表,我会收到错误消息:
Exception: Object is not iterable, try to use .windows()
我的脚本:
import pyautogui
import time
import pyperclip
from pywinauto.application import Application
from win32gui import GetWindowRect, GetForegroundWindow
website = 'https://www.google.com/'
pages = ['Profile 1']
applications = []
try:
for page in pages:
app = Application(backend="uia").start(r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" + str(' --profile-directory="' + str(page) + '"'))
time.sleep(3)
GetWindowRect(GetForegroundWindow())
time.sleep(3)
pyautogui.hotkey('ctrl','l')
for char in str(website):
pyperclip.copy(char)
pyautogui.hotkey('ctrl', 'v')
pyautogui.hotkey('enter')
pyautogui.hotkey('ctrl', 'f5')
print(app)
applications.extend(app)
except Exception as e:
print("Exception: " + str(e))
有没有一种方法可以将应用程序添加到列表中,然后稍后迭代(打开 window)它们?
而不是applications.extend(app)
将当前 window 添加到这样的列表中:
applications.append(GetForegroundWindow())
然后像这样使用它(我的意思是激活浏览器windows):
SetForegroundWindow(applications[0])
两个函数都是win32gui的实现。
我正在尝试在 Python 上自动化处理浏览器 window 的应用程序。
我需要在打开后将应用程序添加到列表中,这样我就可以随时轻松地返回到他们的window。
从下面的代码我可以得到应用程序:pywinauto.application.Application object at 0x0000020C78574FA0
但是如果我尝试从命令 applications.extend(app)
添加到列表,我会收到错误消息:
Exception: Object is not iterable, try to use .windows()
我的脚本:
import pyautogui
import time
import pyperclip
from pywinauto.application import Application
from win32gui import GetWindowRect, GetForegroundWindow
website = 'https://www.google.com/'
pages = ['Profile 1']
applications = []
try:
for page in pages:
app = Application(backend="uia").start(r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" + str(' --profile-directory="' + str(page) + '"'))
time.sleep(3)
GetWindowRect(GetForegroundWindow())
time.sleep(3)
pyautogui.hotkey('ctrl','l')
for char in str(website):
pyperclip.copy(char)
pyautogui.hotkey('ctrl', 'v')
pyautogui.hotkey('enter')
pyautogui.hotkey('ctrl', 'f5')
print(app)
applications.extend(app)
except Exception as e:
print("Exception: " + str(e))
有没有一种方法可以将应用程序添加到列表中,然后稍后迭代(打开 window)它们?
而不是applications.extend(app)
将当前 window 添加到这样的列表中:
applications.append(GetForegroundWindow())
然后像这样使用它(我的意思是激活浏览器windows):
SetForegroundWindow(applications[0])
两个函数都是win32gui的实现。