Window

更新时间:
复制 MD 格式

activate

activate()

Description

Activates the window.

Example- rpa.ui.win32.Window.activate-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.activate()

maximize

maximize()

Description

Maximizes the window.

Example- rpa.ui.win32.Window.maximize-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.maximize()

minimize

minimize()

Description

Minimizes the window.

Example- rpa.ui.win32.Window.minimize-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.minimize()

hide

hide()

Description

Hides the window.

Example- rpa.ui.win32.Window.hide-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.hide()

show

show()

Description

Shows the window.

Example- rpa.ui.win32.Window.show-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.show()

wait_disappear

wait_disappear(timeout=30)

Description

Waits for the window to disappear.

Parameters

timeout<int> The timeout period in seconds.

Example- rpa.ui.win32.Window.wait_disappear-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.wait_disappear()

close

close()

Description

Closes the window.

Example- rpa.ui.win32.Window.close-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.close()

get_element_by_name

get_element_by_name(element, index=1, parent_element=None, timeout=10)

Description

Gets an element object by its name.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

The matching element object<Element>.

Example- rpa.ui.win32.Window.get_element_by_name-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
ele = wnd.get_element_by_name("Notepad Input Box")

count

count(element, parent_element=None)

Description

Gets the number of elements that match the specified name.

Parameters

element<str> The name of the element.

parent_element<Element> The parent element.

Return value

The number of matching elements<int>.

Example- rpa.ui.win32.Window.count-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
ele_count = wnd.count("Notepad Input Box")

wait_loaded

wait_loaded(element, index=1, parent_element=None, timeout=10)

Description

Waits for an element to load. Returns True on success and False on failure.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

True if the element loaded successfully; False otherwise<bool>.

Example- rpa.ui.win32.Window.wait_loaded-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.wait_loaded("Notepad Input Box")

input_text

input_text(element, value, index=1, parent_element=None, simulate=False, replace=True, send_window_message=True, sent_raw=False, wait_mili_seconds=20, timeout=10)

Description

Inputs text into an element.

Parameters

element<str> The name of the element.

value<str> The content to input.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

simulate<bool> Specifies whether to use simulated input.

replace<bool> Specifies whether to clear existing content.

send_window_message<bool> Specifies whether to send a Windows message. This parameter applies only when simulate is False.

sent_raw<bool> Specifies whether to send raw keystrokes. This parameter applies only when simulate is False.

wait_mili_seconds<int> The interval (in milliseconds) between each character input. This parameter applies only when simulate is True. The default is 20, and the maximum is 100. A high value might cause a timeout.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.input_text-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.input_text("Notepad Input Box", "Test it")

input_hotkeys

input_hotkeys(element, value, replace=False, index=1, parent_element=None, timeout=10)

Description

Sends a hotkey or key combination to an element. For more information, see input_hotkey Usage and Virtual-Key Code List.

Parameters

element<str> The name of the element.

value<str> The virtual-key code.

replace<bool> Specifies whether to clear existing content.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.input_hotkeys-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.input_hotkeys("Notepad Input Box", "VK_BACK")

drive_input

drive_input(element, value, replace=True, index=1, parent_element=None, wait_mili_seconds=20, timeout=10)

Description

Uses a driver to simulate keyboard input into the specified element.

Important

For usage restrictions, see Driver Input Usage Restrictions.

Parameters

element<str> The name of the element.

value<str> The content to input.

replace<bool> Specifies whether to clear existing content.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

wait_mili_seconds<int> The interval (in milliseconds) between each character input. The default is 20, and the maximum is 100. A high value might cause a timeout.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.drive_input-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.drive_input("Notepad Input Box", "RpaTest")

click

click(element, button='left', simulate=True, offset_x=0, offset_y=0, index=1, parent_element=None, timeout=10)

Description

Clicks an element. By default, the click occurs at the element's center. Use the offset parameters to click a position relative to the center.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

simulate<bool> Specifies whether to simulate the click.

offset_x<int> The horizontal offset.

offset_y<int> The vertical offset.

button<str> The mouse button.

Options:

  • left: Left button

  • right: Right button

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.click-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.click("Notepad Input Box")

double_click

double_click(element, offset_x=0, offset_y=0, index=1, parent_element=None, simulate=True, timeout=10)

Description

Double-clicks an element. By default, the double-click occurs at the element's center. Use the offset parameters to double-click a position relative to the center.

Parameters

element<str> The name of the element.

offset_x<int> The horizontal offset.

offset_y<int> The vertical offset.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

simulate<bool> Specifies whether to simulate the click.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.double_click-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.double_click("Notepad Input Box")

expand

expand(element, index=1, parent_element=None, timeout=10)

Description

Expands a node in the element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.expand-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.expand("Element Name")

collapse

collapse(element, index=1, parent_element=None, timeout=10)

Description

Collapses a node in the element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.collapse-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.collapse("Element Name")

set_selected_item_by_text

set_selected_item_by_text(element, text, index=1, parent_element=None, timeout=10)

Description

Selects an item in a combo box by its display text.

Parameters

element<str> The name of the element.

text<str> The text of the option to select.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.set_selected_item_by_text-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.set_selected_item_by_text("Element Name", "Item Text")

set_selected_item_by_index

set_selected_item_by_index(element, item_index, index=1, parent_element=None, timeout=10)

Description

Selects an item in a combo box by its index.

Parameters

element<str> The name of the element.

item_index<int> The index of the option to select.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.set_selected_item_by_index-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.set_selected_item_by_index("Element Name", 1)

get_selected_items

get_selected_items(element, mode='selected', index=1, parent_element=None, timeout=10)

Description

Gets all items or only the selected items from a combo box.

Parameters

element<str> The name of the element.

mode<str> The selection mode.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

A list of the option texts<list>.

Example- rpa.ui.win32.Window.get_selected_items-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
selected_items = wnd.get_selected_items("Element Name")

set_checked_state

set_checked_state(element, value=True, index=1, parent_element=None, timeout=10)

Description

Sets the state of a checkbox.

Parameters

element<str> The name of the element.

value<bool> The desired state. True to check the box, False to uncheck it.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.set_checked_state-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.set_checked_state("Element Name", value=True)

get_checked_state

get_checked_state(element, index=1, parent_element=None, timeout=10)

Description

Gets the state of a checkbox.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

True if the checkbox is checked; False otherwise<bool>.

Example- rpa.ui.win32.Window.get_checked_state-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
checked_state = wnd.get_checked_state("Element Name")

get_selected

get_selected(element, index=1, parent_element=None, timeout=10)

Description

Gets the selected state of an element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

True if the element is selected; False otherwise<bool>.

Example- rpa.ui.win32.Window.get_selected-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
checked_state = wnd.get_selected("Element Name")

text

text(element, index=1, parent_element=None, timeout=10)

Description

Gets the text from an element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

The text content of the element<str>.

Example- rpa.ui.win32.Window.text-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
text = wnd.text("Element Name")

pos

pos(element, index=1, parent_element=None, timeout=10)

Description

Gets the coordinates of an element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

A dictionary of the element's coordinates with keys x1, y1, x2, and y2<dict>.

Example- rpa.ui.win32.Window.pos-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
pos = wnd.pos("Element Name")

table

table(element, index=1, parent_element=None, timeout=10)

Description

Gets the content of a table element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

The table content as a list of lists, where each inner list represents a row<list>.

Example- rpa.ui.win32.Window.table-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
table_list = wnd.table("Element Name")

scroll

scroll(element, percent, direction='top', index=1, parent_element=None, timeout=10)

Description

Scrolls the scroll bar to a specified percentage (0-100). Due to limitations in the underlying Windows API, the actual position might deviate by ±1% from the specified value.

Parameters

element<str> The name of the element.

percent<int/float> The scroll percentage.

Options:

  • top: Controls the vertical scroll bar.

  • left: Controls the horizontal scroll bar.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.scroll-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.scroll("Element Name", 50)

get_horizontal_scroll_percent

get_horizontal_scroll_percent(element, index=1, parent_element=None, timeout=10)

Description

Gets the position of the horizontal scroll bar (range: 0-100).

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

The current position of the horizontal scroll bar, as a percentage (0-100)<float>.

Example- rpa.ui.win32.Window.get_horizontal_scroll_percent-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
horizontal_scroll_percent = wnd.get_horizontal_scroll_percent("Element Name")

get_vertical_scroll_percent

get_vertical_scroll_percent(element, index=1, parent_element=None, timeout=10)

Description

Gets the position of the vertical scroll bar (range: 0-100).

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Return value

The current position of the vertical scroll bar, as a percentage (0-100)<float>.

Example- rpa.ui.win32.Window.get_vertical_scroll_percent-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
vertical_scroll_percent = wnd.get_vertical_scroll_percent("Element Name")

screenshot

screenshot(element, file, index=1, parent_element=None, timeout=10)

Description

Takes a screenshot of an element.

Parameters

element<str> The name of the element.

file<str> The full file path where the screenshot will be saved.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.screenshot-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.screenshot("Element Name", r"d:\1.png")

mouse_move

mouse_move(element, index=1, parent_element=None, timeout=10)

Description

Moves the cursor over an element.

Parameters

element<str> The name of the element.

index<int> The index of the target element, used when multiple elements share the same name.

parent_element<Element> The parent element.

timeout<int> The timeout in seconds for waiting for the element.

Example- rpa.ui.win32.Window.mouse_move-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("Notepad", mode="substr")
wnd.mouse_move("Element Name")

set_window_bounding_by_scale

set_window_bounding_by_scale(x1_scale, y1_scale, x2_scale, y2_scale)

Description

Sets the window size and position.

Parameters

x1_scale<float>The x-coordinate of the window's top-left corner, as a proportion of the screen width (0.0 to 1.0).

y1_scale<float>The y-coordinate of the window's top-left corner, as a proportion of the screen height (0.0 to 1.0).

x2_scale<float>The x-coordinate of the window's bottom-right corner, as a proportion of the screen width (0.0 to 1.0).

y2_scale<float>The y-coordinate of the window's bottom-right corner, as a proportion of the screen height (0.0 to 1.0).

Example- rpa.ui.win32.Window.set_window_bounding_by_scale-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("DingTalk", mode="substr")
wnd.set_window_bounding_by_scale(0.1, 0.1, 0.9, 0.9)

get_window_bounding

get_window_bounding()

Description

Gets the window coordinates.

Return value

A dictionary of the window's coordinates with keys x1, y1, x2, and y2<dict>.

Example- rpa.ui.win32.Window.get_window_bounding-

# Notes: None
# Code example:
wnd = rpa.ui.win32.catch("DingTalk", mode="substr")
pos = wnd.get_window_bounding()