Skip to content

Commit

Permalink
Windows: Add "Is Selected" keyword to get the selection state of a ch…
Browse files Browse the repository at this point in the history
…eckbox or a radiobutton
  • Loading branch information
ynerant committed Mar 25, 2024
1 parent 3853cf7 commit 6b1befe
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/windows/src/RPA/Windows/keywords/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,47 @@ def set_notepad_size():
)
return element

@keyword(tags=["action"])
def is_selected(self, locator: Locator) -> Optional[bool]:
"""Get the selection state of the element defined by the provided `locator`.
The ``ActionNotPossible`` exception is raised if the identified element doesn't
support selection item retrieval.
:param locator: String locator or element object.
:returns: Optionally the selection state of the identified element, as a boolean.
**Example: Robot Framework**
.. code-block:: robotframework
${value} = Is Selected type:RadioButtonControl name:Apple
**Example: Python**
.. code-block:: python
from RPA.Windows import Windows
lib_win = Windows()
value = lib_win.is_selected("type:RadioButtonControl name:Apple")
print(value)
"""
element = self.ctx.get_element(locator)
get_selection_item_pattern = getattr(element.item, "GetSelectionItemPattern", None)

if get_selection_item_pattern:
func_name = get_selection_item_pattern.__name__
self.logger.info(
"Retrieving the element selection state with the %r method.", func_name
)
selection_item_pattern = get_selection_item_pattern()
return selection_item_pattern.IsSelected if selection_item_pattern else None

raise ActionNotPossible(
f"Element found with {locator!r} doesn't support selection item retrieval"
)

@keyword(tags=["action", "keyboard"])
def send_keys(
self,
Expand Down

0 comments on commit 6b1befe

Please sign in to comment.