簡體   English   中英

如何使用 WinAppDriver (Python) 切換到已經運行的應用程序

[英]How to switch to an already running application using WinAppDriver (Python)

我想在 MS Store 和 Chrome 瀏覽器之間切換。 如何使用 WinAppDriver 切換應用程序?

我正在調查https://github.com/microsoft/WinAppDriver/issues/534 ,在 C# 中找到了一些建議,但不幸的是,它們不適用於 python 並更新了 appium/selenium。

這是我連接到根的代碼

desired_caps = {}
desired_caps["app"]="Root"
session = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities= desired_caps)

print(session.current_window_handle)
#it prints current window handle

接下來,我試圖獲取所有返回 Null 的處理程序,

windows = session.window_handles

我找到了一個解決方法,找到你想要的應用程序 WindowHandle,然后使用提取的 WindowHandle 直接創建 session。 從根遍歷是不值得的。 我發現很多人都在抱怨如何切換我希望這會有所幫助!

import win32gui

def findWindowHandle():
    handleList = []
    def findit(hwnd,ctx):
        if win32gui.GetWindowText(hwnd) == "Microsoft Store": # check the title
            handleList.append(hwnd)

    win32gui.EnumWindows(findit,None)
    return handleList

handle = hex(findWindowHandle()[0])
print(handle)


desired_caps = {}
desired_caps["appTopLevelWindow"] = handle
desired_caps["deviceName"]="WindowsPC"
desired_caps["platformName"]="Windows"
session = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities= desired_caps)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM