Windows
The Windows module has functionality to inspect and manipulate the Windows of the desktop.
All windows
The all()
method will return an array of window proxy objects representing all windows on the desktop.
Example
var allWindows = Windows.all();
Windows for current application
The forApp()
method returns an array of window proxy objects representing all the windows of the application.
Example
var applicationWindows = Windows.forApp();
Primary window
The primary
property returns a single window proxy object representing the primary or main window of the application.
Example
var pw = Windows.primary;
Frontmost/focused window
Get the frontmost or focused window with this command.
Example
var w = Windows.focused;
// and the same can be done via
w = Windows.frontMost;
Given a window handle
Get access to a window if you know its handle.
// 12345 is probably not a valid handle, I'm an example ...
var w = Windows.byHwnd(12345);
Window Proxy
The window proxy object returned by the Windows
module methods represents a desktop window and can be manipulated with the following methods and properties.
Close
Close the window.
Windows.primary.close();
Move
Move the window to the given x,y
coordinates.
var pw = Windows.primary;
// Move the window to (100,100) from the topmost left corner of the screen.
pw.move(100, 100);
Resize
Resize the window to the given dimensions.
var pw = Windows.primary;
pw.resize(100, 100);
Focus
Make the window the focused (topmost) window.
var pw = Windows.primary;
pw.focus();
Maximize
Maximize the window.
var pw = Windows.primary;
pw.maximize();
Minimize
Minimize the window.
var pw = Windows.primary;
pw.minimize();
Show
Show a hidden window.
Windows.primary.show();
Restore
Restore the original state of the window (after having maximized or minimized it).
var pw = Windows.primary;
pw.restore();
Screenshot
Grab a screenshot of the window. The screenshot will be returned as a base64 encoded string. Accepts an optional options object.
options
optional object with options for screenshot, supported options:focus
[bool] whether to focus the window prior to taking the screenshot - defaults to true
var pw = Windows.primary;
// img is a base64 encoded string
var img = pw.screenshot();
// get screenshot without setting focus first
var img2 = pw.screenshot({ focus: false });
SendKeys
Send keyboard strokes to the window.
var pw = Windows.primary;
pw.sendKeys("abc");
Hwnd
Get the window handle of the window.
var pw = Windows.primary;
var hwnd = pw.hwnd;
Title
Get the title of the window.
var pw = Windows.primary;
var t = pw.title;
Class
Get the class of the window.
var pw = Windows.primary;
var t = pw.class;
IsPrimary
Get/set whether this window is considered the primary for the application.
var ws = Windows.forApp();
if (!ws[0].isPrimary) {
ws[0].isPrimary = true;
}
IsMaximized
Get a boolean value indicating whether or not the window is maximized.
var ws = Windows.forApp();
if (!ws[0].isMaximized) {
// do something then
}
IsMinimized
Get a boolean value indicating whether or not the window is minimized.
var ws = Windows.forApp();
if (!ws[0].isMinimized) {
// do something then
}
Bounds
Get/set the bounds (location and size) of the window.
var pw = Windows.primary;
var bounds = pw.bounds;
// Move 10px left and down
bounds.x = bounds.x + 10;
bounds.y = bounds.y + 10;
// Decrease width and height with 10px
bounds.width = bounds.width - 10;
bounds.height = bounds.height - 10;
// Update the window bounds with the new values
pw.bounds = bounds;
Process for window
window.process();
// is a ProcessProxy object
Native field actions for window
Carry out a field action on the window using the native driver. This can be useful in various situations:
- Dealing with native dialogs in a java/chrome/firefox/edge apps without having to create an additional native app
- Identifying a window based on presence of a specific field
The window.field(path)
method returns a normal field object backed by a native app driver. See the Field documentation for a full description of available actions.
window.field("**/(name)OK").click();
Transparency
A transparency
property. The value to set is between 0 and 255. 0 is fully transparent, 255 is fully opaque.
Windows.primary.transparency = 60;
Dialog.info("Transparency is " + Windows.primary.transparency, "");
Native field in window
Resolve a field in the given window using the native driver. This is particularly useful for interacting with native dialogs in browser apps such as a printer dialog or a file dialog in a Chrome app. It may also be useful for java apps embedded in a native shell. The field
method returns a field object with the usual See methods/properties.
// This could be a case of a chrome flow that needs to pick a file for upload
window.field("**/(type)edit").input("C:\\aFolder\\aFile.txt");
window.field("**/Ok").click();