Windows

Windows

class firefox_puppeteer.ui.windows.Windows(marionette)
all

Retrieves a list of all open chrome windows.

Returns:List of BaseWindow instances corresponding to the windows in marionette.chrome_window_handles.
close(handle)

Closes the chrome window with the given handle.

Parameters:handle – The handle of the chrome window.
close_all(exceptions=None)

Closes all open chrome windows.

There is an optional exceptions list, which can be used to exclude specific chrome windows from being closed.

Parameters:exceptions – Optional, list of BaseWindow instances not to close.
create_window_instance(handle, expected_class=None)

Creates a BaseWindow instance for the given chrome window.

Parameters:
  • handle – The handle of the chrome window.
  • expected_class – Optional, check for the correct window class.
current

Retrieves the currently selected chrome window.

Returns:The BaseWindow for the currently active window.
focus(handle)

Focuses the chrome window with the given handle.

Parameters:handle – The handle of the chrome window.
focused_chrome_window_handle

Returns the currently focused chrome window handle.

Returns:The window handle of the focused chrome window.
loaded(handle)

Check if the chrome window with the given handle has been completed loading.

Parameters:handle – The handle of the chrome window.
Returns:True, if the chrome window has been loaded.
classmethod register_window(window_type, window_class)

Registers a chrome window with this class so that this class may in turn create the appropriate window instance later on.

Parameters:
  • window_type – The type of window.
  • window_class – The constructor of the window
switch_to(target)

Switches context to the specified chrome window.

Parameters:target – The window to switch to. target can be a handle or a callback that returns True in the context of the desired window.
Returns:Instance of the selected BaseWindow.

BaseWindow

class firefox_puppeteer.ui.windows.BaseWindow(marionette, window_handle)

Base class for any kind of chrome window.

close(callback=None, force=False)

Closes the current chrome window.

If this is the last remaining window, the Marionette session is ended.

Parameters:
  • callback – Optional, function to trigger the window to open. It is triggered with the current BaseWindow as parameter. Defaults to window.open().
  • force – Optional, forces the closing of the window by using the Gecko API. Defaults to False.
closed

Returns closed state of the chrome window.

Returns:True if the window has been closed.
focus()

Sets the focus to the current chrome window.

focused

Returns True if the chrome window is focused.

Returns:True if the window is focused.
handle

Returns the window handle of the chrome window.

Returns:window handle.
loaded

Checks if the window has been fully loaded.

Returns:True, if the window is loaded.
localize_entity(entity_id)

Returns the localized string for the specified DTD entity id.

Parameters:entity_id – The id to retrieve the value from.
Returns:The localized string for the requested entity.
Raises:MarionetteException – When entity id is not found.
localize_property(property_id)

Returns the localized string for the specified property id.

Parameters:property_id – The id to retrieve the value from.
Returns:The localized string for the requested property.
Raises:MarionetteException – When property id is not found.
menubar

Provides access to the menu bar, for example, the File menu.

See the MenuBar reference.

open_window(callback=None, expected_window_class=None, focus=True)

Opens a new top-level chrome window.

Parameters:
  • callback – Optional, function to trigger the window to open. It is triggered with the current BaseWindow as parameter. Defaults to window.open().
  • expected_class – Optional, check for the correct window class.
  • focus – Optional, if true, focus the new window. Defaults to True.
send_shortcut(command_key, **kwargs)

Sends a keyboard shortcut to the window.

Parameters:
  • command_key – The key (usually a letter) to be pressed.
  • accel – Optional, If True, the Accel modifier key is pressed. This key differs between OS X (Meta) and Linux/Windows (Ctrl). Defaults to False.
  • alt – Optional, If True, the Alt modifier key is pressed. Defaults to False.
  • ctrl – Optional, If True, the Ctrl modifier key is pressed. Defaults to False.
  • meta – Optional, If True, the Meta modifier key is pressed. Defaults to False.
  • shift – Optional, If True, the Shift modifier key is pressed. Defaults to False.
switch_to(focus=False)

Switches the context to this chrome window.

By default it will not focus the window. If that behavior is wanted, the focus parameter can be used.

Parameters:focus – If True, the chrome window will be focused.
Returns:Current window as BaseWindow instance.
window_element

Returns the inner DOM window element.

Returns:DOM window element.