Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Add "Is Selected" keyword #1163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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