Can't get Window object for apps with more than one "main" window
See original GitHub issueDescribe the bug For example, Google Chrome can have multiple open windows, but FlaUI only allows getting the automation controls for the “main” one, which is arbitrary. It’d be great if there was either a GetMainWindows method, or just a FromHandle method like AutomationElement has.
Code snippets
var app = FlaUI.Core.Application.Attach("chrome.exe");
using (var automation = new UIA3Automation())
{
var window = app.GetMainWindow(automation);
Currently, I can’t use the library, I instead have to enumerate the windows manually (I use the https://github.com/zastrowm/Win32Interop.WinHandles library for this), and use the built-in .NET automation library:
foreach (var window in EnumerateWindows(chromeProcess))
{
AutomationElement root = AutomationElement.FromHandle(window);
...
}
static IEnumerable<IntPtr> EnumerateWindows(Process process)
{
return TopLevelWindowUtils.FindWindows(w => w.IsVisible())
.Where(w =>
{
PInvoke.GetWindowThreadProcessId(w.RawPtr, out uint processId);
return processId == process.Id;
})
.Select(w => w.RawPtr);
}
Issue Analytics
- State:
- Created a year ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
How to share the same window object with the other web ...
The problem is that the new page is creating its own window object and cannot access the properties/methods of the first page's window...
Read more >Show multiple views with AppWindow
Use the AppWindow class to view different parts of your app in separate windows.
Read more >Multi-window support
Quickly bring your app to life with less code, using a modern declarative approach to UI, and the simplicity of Kotlin. ... Start...
Read more >How to Handle Multiple Windows in an Electron App
In Electron, each window corresponds to a renderer process. Here's a way of setting up the logic of handling multiple windows in the...
Read more >Multiple windows in PyQt5
In Qt any widget without a parent is a window. This means, to show a new window you just need to create a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One thing to consider with
GetAllTopLevelWindows
is that it returns only top-level windows, like the main window, not its child windows. To get the windows that are opened by the main window try:I get different results with that. I tried it using Chrome with two windows open: