Skip to content

Optimize tap loop by hoisting element finding and calculations#475

Merged
emanlove merged 2 commits intoserhatbolsu:masterfrom
Dor-bl:performance-optimization-tap-loop-16219237186636556862
Mar 10, 2026
Merged

Optimize tap loop by hoisting element finding and calculations#475
emanlove merged 2 commits intoserhatbolsu:masterfrom
Dor-bl:performance-optimization-tap-loop-16219237186636556862

Conversation

@Dor-bl
Copy link
Copy Markdown
Contributor

@Dor-bl Dor-bl commented Mar 9, 2026

Implements

This pull request makes a small adjustment to the tap method in the AppiumLibrary/keywords/_touch.py file. The change corrects the placement of the loop that handles multiple taps when the element is a string locator, ensuring that the element is only found once and then tapped multiple times as intended.

  • Fixed the tap method so that when tapping on an element found by a string locator, the element is located once and then tapped the specified number of times, improving efficiency and correctness.

Fixing

Dor-bl added 2 commits March 8, 2026 20:46
…ate calculation.

This change moves the `_element_find` call and the center coordinate calculations outside the repetition loop in the `tap` keyword. This avoids making multiple expensive Appium server calls for the same element when the `count` argument is greater than 1.

Key changes:
- Hoisted `self._element_find(element, True, True)` outside the loop.
- Hoisted `location` and `size` retrieval and `center_x`, `center_y` calculations outside the loop.
- The `driver.tap` call remains inside the loop to perform the requested number of taps at the calculated position.

Performance impact:
- Number of `_element_find` calls reduced from `count` to 1.
- Significant reduction in network/IPC latency for multi-tap operations.
Copy link
Copy Markdown
Contributor

@chsinger chsinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvement :)

@emanlove emanlove merged commit f7f56cb into serhatbolsu:master Mar 10, 2026
2 checks passed
@emanlove emanlove added enhancement Acknowledge Acknowledge within Release Notes and removed needs review labels Mar 10, 2026
@emanlove emanlove added this to the v3.3 milestone Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Acknowledge Acknowledge within Release Notes enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants