Skip to content

Commit 8d41078

Browse files
NepitwinAndreas Sekulski
andauthored
Adjustment in COMExcpetion handling and typo (#239)
Co-authored-by: Andreas Sekulski <andreas.sekulski@gdata.de>
1 parent 736c7f6 commit 8d41078

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
77

88
## [Unreleased][]
99

10+
### Added
11+
- COMException handling implemented for get element method to avoid COMException raise to robotframework-flaui
12+
13+
### Changed
14+
15+
- Typo adjustments in parameter timeout_between_repeates to timeout_between_repeats for all mouse keywords
16+
1017
## [Release][4.0.2] [4.0.2][4.0.1-4.0.2] - 2025-10-17
1118

1219
### Added

src/FlaUILibrary/flaui/module/element.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Optional, Any, Union
44
from System import Exception as CSharpException # pylint: disable=import-error
55
from System import InvalidOperationException # pylint: disable=import-error
6+
from System.Runtime.InteropServices import COMException # pylint: disable=import-error
67
from FlaUI.Core import Debug as FlaUIDebug # pylint: disable=import-error
78
from FlaUI.Core.Exceptions import PropertyNotSupportedException # pylint: disable=import-error
89
from FlaUI.Core.Exceptions import ElementNotAvailableException # pylint: disable=import-error
@@ -141,9 +142,6 @@ def _get_name_from_element(self, xpath: str):
141142
142143
Args:
143144
xpath (string): XPath identifier from element.
144-
145-
Raises:
146-
COMException: If node don't exist.
147145
"""
148146
return self._get_element(xpath).Name
149147

@@ -153,9 +151,6 @@ def _get_rectangle_bounding_from_element(self, xpath: str):
153151
154152
Args:
155153
xpath (string): XPath identifier from element.
156-
157-
Raises:
158-
COMException: If node don't exist.
159154
"""
160155
rect = self._get_element(xpath).BoundingRectangle
161156
return [Converter.cast_to_int(rect.X),
@@ -207,19 +202,15 @@ def _get_element(self, xpath: str):
207202
Raises:
208203
FlaUiError: If node could not be found by xpath.
209204
"""
210-
try:
205+
component = self._get_element_by_xpath(xpath)
206+
if not component and self._timeout > 0:
207+
time.sleep(self._timeout / 1000)
211208
component = self._get_element_by_xpath(xpath)
212-
if not component and self._timeout > 0:
213-
time.sleep(self._timeout / 1000)
214-
component = self._get_element_by_xpath(xpath)
215209

216-
if component:
217-
return component
210+
if component:
211+
return component
218212

219-
raise FlaUiError(FlaUiError.XPathNotFound.format(xpath))
220-
221-
except CSharpException:
222-
raise FlaUiError(FlaUiError.XPathNotFound.format(xpath)) from None
213+
raise FlaUiError(FlaUiError.XPathNotFound.format(xpath))
223214

224215
def _get_element_by_xpath(self, xpath: str):
225216
"""
@@ -232,6 +223,10 @@ def _get_element_by_xpath(self, xpath: str):
232223
return self._automation.GetDesktop().FindFirstByXPath(xpath)
233224
except ElementNotAvailableException:
234225
return None
226+
except COMException:
227+
return None
228+
except CSharpException:
229+
return None
235230

236231
def _find_all_elements(self, xpath: str):
237232
"""

0 commit comments

Comments
 (0)