Skip to content

Commit f8df36b

Browse files
committed
click text keyword added.
1 parent 7ff445c commit f8df36b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/AppiumLibrary/keywords/_element.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ def click_button(self, index_or_name):
4949
class_name = self._get_class(_platform_class_dict)
5050
self._click_element_by_class_name(class_name, index_or_name)
5151

52+
def click_text(self, text, exact_match=False):
53+
"""Click text identified by ``text``.
54+
55+
By default tries to click any text involves given ``text``, if you would
56+
like to click exactly matching text, then set ``exact_match`` to `True`.
57+
58+
If there are multiple use of ``text`` use `Get Web Elements`.
59+
60+
New in AppiumLibrary 1.4.
61+
"""
62+
_platform_class_dict = {'ios': 'name', 'android': 'text'}
63+
if exact_match:
64+
_xpath = '//*[@{}="{}"]'.format(
65+
_platform_class_dict.get(self._get_platform()),
66+
text)
67+
else:
68+
_xpath = '//*[contains(@{},"{}")]'.format(
69+
_platform_class_dict.get(self._get_platform()),
70+
text)
71+
self._element_find(_xpath, True, True).click()
72+
5273
def input_text(self, locator, text):
5374
"""Types the given `text` into text field identified by `locator`.
5475

0 commit comments

Comments
 (0)