Description
I'm playing with WInAppDriver in Python following Python examples I find on-line but am stuck on the very basic issue of finding my app's main window. To illustrate, I can start my app easily with:
from appium import webdriver
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723',
desired_capabilities={
"debugConnectToRunningApp": 'false',
"app": PathToExe
})
and I can see driver is: <appium.webdriver.webdriver.WebDriver (session="F33897D8-7C32-4071-BF7F-FC316B21FA77")>
But this is not a web element it's a driver. I want the main window. I can get it's handle using driver.current_window_handle
but that isn't an element and I can't find a way to get or find an element from a window handle.
It eventuates that this does return an element:
window = driver.find_element_by_xpath('*')
print(f"Provider: {window.get_attribute('ProviderDescription')}")
and window is <appium.webdriver.webelement.WebElement (session="F33897D8-7C32-4071-BF7F-FC316B21FA77", element="42.1444382")>
So we have an element now. And I can get attributes from it. ProviderDescription is an interesting attribute and is:
Provider: [pid:8680,providerId:0x160A1E Main:Nested [pid:37148,providerId:0x160A1E Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]
When I check the PIDs here I see 8680 is the WinAppDriver.exe PID and 37148 is my app's PID. It seems to be nested as Main.
I can look at window.id
and check in inspect.exe this not the ID of my apps window. Alas inspect.exe provides no means for me to search on that id to find what it is and I've not been able to locate it manually, but I suspect it's related to WinAppDriver.exe (i.e PID 8680 above, not PID 37148).
What remains a mystery is:
- How can one get the Main window element?
- How can one get all its child elements
On 2, I find (using window
above):
children = window.find_elements_by_xpath('*/*')
produces an empty list in children
. No surprise as window
seems to be related to WinAppDriver and not the main window of my app!