robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.12k stars 215 forks source link

RPA.Windows. Add keywords to support element details #518

Open mikahanninen opened 2 years ago

mikahanninen commented 2 years ago

At the moment WindowsElement contains property item which represents underlying Control object of the uiautomation package.

Property contains details which could be exposed as keywords and/or listed as properties in the WindowsElement object.

mikahanninen commented 1 year ago

Add possibility to identify elements based on their properties like currently selected element in the list of elements.

customer feedback:

_There doesn't seem to be a solution without using the underlying UIAutomation library by using the item field of the WindowsElement object, like so: select_pattern = list_control_elem.item.GetSelectionPattern() return selectpattern.GetSelection()[0].Name This is a bad solution since I'm skipping a layer and creating an unwanted dependency. RPA.Windows should provide at least wrappers for all UI functions. Same issue occurs with other patterns like GetTogglePattern().

magrosso commented 1 year ago

Here's a list of the patterns we're currently using:

To check if an item is selected:

select_pattern = control.item.GetSelectionItemPattern() return select_pattern.IsSelected

To get the select item from list or combobox

select_pattern = list_control_elem.item.GetSelectionPattern() return select_pattern.GetSelection()[0].Name

To get the state of a toggle:

switch = switch_control.item.GetTogglePattern() return switch.ToggleState == 1 if switch_state else switch.ToggleState == 0

To set a slider value:

pattern = control.item.GetRangeValuePattern() pattern.SetValue(set_value)

magrosso commented 1 year ago

We're also using the table pattern:

laser_pattern = laser_table.item.GetTablePattern() col_headers = laser_pattern.GetColumnHeaders()

kkotenko commented 6 months ago

Additionally to those mentioned, in my project, I have found myself using properties like item.IsEnabled and item.HasKeyboardFocus. However, item.GetSelectionPattern().GetSelection()[0].Name is by far the one I use most often.