Skip to content

Commit

Permalink
#160 Property exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Sekulski committed Mar 1, 2024
1 parent b7c577a commit 48458fd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions TestApplications/TestApplications.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApplication", "src\WpfApplication\WpfApplication.csproj", "{C8276299-FA43-409B-A969-EF030AB56224}"
EndProject
Expand Down
52 changes: 46 additions & 6 deletions src/FlaUILibrary/flaui/module/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from enum import Enum
from typing import Optional, Any
from System import Exception as CSharpException # pylint: disable=import-error
from FlaUI.Core import Debug as FlaUIDebug # pylint: disable=import-error
from FlaUI.Core import Debug as FlaUIDebug # pylint: disable=import-error
from FlaUI.Core.Exceptions import PropertyNotSupportedException # pylint: disable=import-error
from FlaUILibrary.flaui.util.converter import Converter
from FlaUILibrary.flaui.exception import FlaUiError
from FlaUILibrary.flaui.interface import (ModuleInterface, ValueContainer)
Expand Down Expand Up @@ -61,7 +62,7 @@ def __init__(self, automation: Any, timeout: int = 1000):
self._timeout = timeout

@staticmethod
def create_value_container(name=None, xpath=None, retries=None, use_exception=None, msg=None):
def create_value_container(name=None, xpath=None, retries=None, use_exception=None, msg=None):
"""
Helper to create container object.
Expand Down Expand Up @@ -98,7 +99,7 @@ def execute_action(self, action: Action, values: Container):
lambda: self._get_name_from_element(values["xpath"]),
self.Action.GET_ELEMENT_RECTANGLE_BOUNDING:
lambda: self._get_rectangle_bounding_from_element(
values["xpath"]),
values["xpath"]),
self.Action.IS_ELEMENT_ENABLED:
lambda: self._get_element(values["xpath"]).IsEnabled,
self.Action.NAME_SHOULD_BE:
Expand Down Expand Up @@ -229,9 +230,9 @@ def _find_all_elements(self, xpath: str):
elements = self._get_all_elements_by_xpath(xpath)
for element in elements:
values.append(AutomationElement(
element.AutomationId,
element.Name,
element.ClassName,
self._try_get_automation_id_property(element),
self._try_get_name_property(element),
self._try_get_classname_property(element),
FlaUIDebug.GetXPathToElement(element)
))

Expand Down Expand Up @@ -456,3 +457,42 @@ def _set_timeout(self, timeout: int):
timeout (Number): Timeout value in seconds
"""
self._timeout = timeout

@staticmethod
def _try_get_automation_id_property(element):
"""
Try to get automation id property from element. Return empty string if failed.
Args:
element (UIA): AutomationElement.
"""
try:
return element.AutomationId
except PropertyNotSupportedException:
return ""

@staticmethod
def _try_get_name_property(element):
"""
Try to get name property from element. Return empty string if failed.
Args:
element (UIA): AutomationElement.
"""
try:
return element.Name
except PropertyNotSupportedException:
return ""

@staticmethod
def _try_get_classname_property(element):
"""
Try to get class name property from element. Return empty string if failed.
Args:
element (UIA): AutomationElement.
"""
try:
return element.ClassName
except PropertyNotSupportedException:
return ""

0 comments on commit 48458fd

Please sign in to comment.