Skip to content

Commit f7f56cb

Browse files
authored
Merge pull request #475 from Dor-bl/performance-optimization-tap-loop-16219237186636556862
Optimize tap loop by hoisting element finding and calculations
2 parents 9098b9e + b4f6bb3 commit f7f56cb

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

AppiumLibrary/keywords/_touch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ def tap(self, element: Union[str, list], count:int = 1, duration=timedelta(secon
326326
raise ValueError(f"Invalid coordinates format: {element}. Expected a list like [x, y]")
327327

328328
elif isinstance(element, str):
329+
el = self._element_find(element, True, True)
330+
location = el.location
331+
size = el.size
332+
center_x = location['x'] + size['width'] // 2
333+
center_y = location['y'] + size['height'] // 2
329334
for _ in range(count):
330-
el = self._element_find(element, True, True)
331-
location = el.location
332-
size = el.size
333-
center_x = location['x'] + size['width'] // 2
334-
center_y = location['y'] + size['height'] // 2
335335
driver.tap([(center_x, center_y)], duration.total_seconds() * 1000)
336336

337337
else:

0 commit comments

Comments
 (0)