Skip to content

Commit c50feab

Browse files
authored
Merge pull request #140 from serhatbolsu/feature/unicode-handling
Feature/unicode handling
2 parents 1c2af11 + 0e37a03 commit c50feab

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

CHANGES.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
History
22
=======
3+
1.4.1
4+
----------------
5+
- Unicode better support
6+
- Unicode supported now inside xpath text.
7+
- Click Text iOS handling is much better now. Works regardless if text is name, value or label
8+
9+
1.4.0
10+
----------------
11+
- New finding elements strategy now supports directly using WebElement. Check keyword documentation for more information.
12+
- Added default locator strategies. Default is: id and xpath check library introduction for more details.
13+
- Click Text added as keyword in which you can directly click on found texts. Underlying it works on predefined xpath depending on platform.
14+
- Unicode fixes also reflected on Page Should Contain Text and Page Should Not Contain Text
15+
- Getting an element text is added and its helper keywords.
16+
317
1.3.7
418
----------------
519
- ``swipe`` critical bug fix <https://github.com/jollychang/robotframework-appiumlibrary/pull/125>

src/AppiumLibrary/keywords/_element.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .keywordgroup import KeywordGroup
55
from robot.libraries.BuiltIn import BuiltIn
66
import ast
7-
import unicodedata
7+
from unicodedata import normalize
88
from selenium.webdriver.remote.webelement import WebElement
99

1010
try:
@@ -55,20 +55,27 @@ def click_text(self, text, exact_match=False):
5555
By default tries to click first text involves given ``text``, if you would
5656
like to click exactly matching text, then set ``exact_match`` to `True`.
5757
58-
If there are multiple use of ``text`` use `locator` with `Get Web Elements` instead.
58+
If there are multiple use of ``text`` and you do not want first one,
59+
use `locator` with `Get Web Elements` instead.
5960
6061
New in AppiumLibrary 1.4.
6162
"""
62-
_platform_class_dict = {'ios': 'name', 'android': 'text'}
63-
if exact_match:
64-
_xpath = u'//*[@{}="{}"]'.format(
65-
_platform_class_dict.get(self._get_platform()),
66-
text)
67-
else:
68-
_xpath = u'//*[contains(@{},"{}")]'.format(
69-
_platform_class_dict.get(self._get_platform()),
70-
text)
71-
self._element_find(_xpath, True, True).click()
63+
if self._get_platform() == 'ios':
64+
element = self._element_find(text, True, False)
65+
if element:
66+
element.click()
67+
else:
68+
if exact_match:
69+
_xpath = u'//*[@value="{}" or @label="{}"]'.format(text, text)
70+
else:
71+
_xpath = u'//*[contains(@label,"{}") or contains(@value, "{}")]'.format(text, text)
72+
self._element_find(_xpath, True, True).click()
73+
elif self._get_platform() == 'android':
74+
if exact_match:
75+
_xpath = u'//*[@{}="{}"]'.format('text', text)
76+
else:
77+
_xpath = u'//*[contains(@{},"{}")]'.format('text', text)
78+
self._element_find(_xpath, True, True).click()
7279

7380
def input_text(self, locator, text):
7481
"""Types the given `text` into text field identified by `locator`.
@@ -548,7 +555,12 @@ def _element_input_value_by_locator(self, locator, text):
548555
def _element_find(self, locator, first_only, required, tag=None):
549556
application = self._current_application()
550557
if isstr(locator):
551-
elements = self._element_finder.find(application, locator, tag)
558+
# Normalize any unicode as explained here, http://appium.io/slate/en/master/?javascript#multi-lingual-support
559+
if self._get_platform() == 'ios':
560+
_locator = normalize('NFD', locator)
561+
else:
562+
_locator = locator
563+
elements = self._element_finder.find(application, _locator, tag)
552564
if required and len(elements) == 0:
553565
raise ValueError("Element locator '" + locator + "' did not match any elements.")
554566
if first_only:
@@ -567,10 +579,8 @@ def _get_text(self, locator):
567579
return None
568580

569581
def _is_text_present(self, text):
570-
text_norm = unicodedata.normalize(
571-
'NFD', text).encode('ascii', 'ignore')
572-
source_norm = unicodedata.normalize(
573-
'NFD', self.get_source()).encode('ascii', 'ignore')
582+
text_norm = normalize('NFD', text).encode('ascii', 'ignore')
583+
source_norm = normalize('NFD', self.get_source()).encode('ascii', 'ignore')
574584
return text_norm in source_norm
575585

576586
def _is_element_present(self, locator):

src/AppiumLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
VERSION = '1.4.0.1'
3+
VERSION = '1.4.1'

0 commit comments

Comments
 (0)